5 Docker Commands You Need to Know
It’s not an exaggeration to say that Docker has changed the way developers and engineers do their jobs. It gives you a way to move code between systems, improve security, and decouple dependencies between applications. So if you’re not already using Docker as part of your development process, it’s time to give it a close look.
In this article, you’ll learn five useful Docker commands. They’ll get you started on your way to mastering this valuable tool.
#1: Run a Container With Docker
The first Docker command you need to know is how to start an image. The good news is that it’s easy!
Run has an extensive set of command-line arguments. You can get them with Docker run -help.
For the “hello-world” image, we didn’t use any options. But the banner it displayed gave us a hint. Let’s try running the Ubuntu container that “hello-world” recommended in its banner message.
#2: List Processes With Docker
Now you’ve seen how easy it is to run containers. Let’s take a look at how to check on them.
Leave the Ubuntu container running in one terminal and run this in another:
#3: Stop and Remove Docker Containers
Let’s stop the Ubuntu container. On your system, use the name Docker chose.
Now, rerun Docker ps. The listing is empty. Is the container gone?
Let’s try adding another option to Docker ps.
Let’s get rid of the “hello-worlds.”
After running Docker rm, Docker ps verifies that the “hello-world(s)” are gone.
So, to remove a container, pass Docker rm and the container’s name. You can pass in more than one name too.
#4: Restart and Connect to Containers
You left the Ubuntu container stopped on your system. Let’s use the Docker commands for restarting and using it.
Docker start restarts a stopped container. This is important for services like a web server or microservice that you want to stop to save on cloud costs and then quickly restart when needed. Docker containers start much faster than virtual machines.
Docker exec executes a command inside a running container. The command-line arguments are similar to run, but instead of an image name, you specify a container loaded and started.
#5: Name Your Containers
That name for your Ubuntu container isn’t very helpful, is it? If you were to leave a bunch of containers and then come back a few days later, you might have trouble telling them apart.
First, let’s get rid of that container.
Now, let’s start it with a more useful name.
Five Docker Commands
You now know how to start and stop Docker containers. You also learned how to give your containers custom names so they’re easier to keep track of. Finally, you’ve seen how to stop and restart containers and how to clean images on your system.
Don’t stop here. Check out Cprime’s Docker Containerization Boot Camp, a three-day hands-on workshop that will show you how to simplify your application development radically.