5 Commands to Get You Up and Running With Docker

DZone 's Guide to

5 Commands to Get You Up and Running With Docker

Perfect for beginners, this list of Docker commands will get you started with containers.

· Cloud Zone ·
Free Resource

Docker has revolutionized the way software is being written and deployed throughout our industry. With the use of its lightweight containers, you can deploy your whole environment locally – or in your client's machine — quickly and easily.

We’ve used Docker at Practical Software to test how multiple servers behave when one of them crashes and burns, and it's become extremely handy when we’ve needed to test code on a specific Linux distribution and didn't have a lot of time to install it from scratch.

When I first started to learn about Docker (and then orchestration), it seemed to me that the more I learned, the more I didn't understand. I just needed to try it out.

And so I bring before you my list of commands that helped me start using Docker:

1. docker run

Right after you’ve installed Docker on your machine, you'll want to try it out. Head over to DockerHub and find a container you want to use. It could be a database or service you use.

And once you find your image of choice, just write:

docker run <container name> 

If you go to that container page, there’s a good chance you can find additional parameters you can use to determine how the container behaves, and you will probably want to expose one or more ports to the outside world as well.

So if you wanted to start a new container running PostgreSQL, this is all you need to run:

docker run –e POSTGRES_USER=dror –p 5432:5432 postgres:latest 

  • -e is for passing parameters — in this case, the DB admin user name

  • -p exposes the container's port 5432 as my machine’s port so I can reach it using localhost:5432

2. docker ps

Once you have a few containers up and running you might want to see how are they doing or take a quick inventory of what you have. For that y,ou have the ps command

Just run docker ps to see a list of running containers or docker ps -a to show all of the containers.

3. docker stop

As the name implies, it stops a running container:

docker stop 552470331f33 

Then the first container would have stopped running.

You can combine docker stop and docker ps to stop all running containers:

docker stop $(docker ps -q)  

Written in PowerShell, that command will get a list of all of the running container IDs (this is what the -q is for) and stop them

4. docker logs

docker log is used to show the output and errors written by applications running inside your containers. This is especially useful if (read: when) they crash. You can see the logs from the past or you can use -f just like good old tail to see it in real time.

5. docker system prune

After you’ve used Docker for a while, things tend to pile up: old container images, unused networks, and quite a lot of junk. To remove all of this unused data, run docker system prune and boldly approve when Docker insists on checking if you really, really know what you’re doing.


That’s it for now. Obviously, there’s still quite a lot to learn in order to use Docker in production, but the first step of installing Docker and getting your hands dirty is simple enough.

Happy coding…

cloud, docker, docker commands

Published at DZone with permission of Dror Helper , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}