As part of my back to basics series I thought I would create an article on base Docker container commands. Obviously, there are a lot more ways to dig into the CLI but this is a good set of commands to start with.

$ docker run -it <image name>
This will allow you to go into an interactive terminal and issue traditional commands.
My example is ubuntu, as you can see I ran the simple #ps -elf command and the # cat /etc/*release* to receive output from the ubuntu OS.

$ docker run -d <image name> sleep <number>
-d allows us to start a container in detached mode so it doesn’t consume our terminal
The sleep command gives the container an action that will prevent it from immediately exiting and stopping

$ docker run -td <image>
If you do not wish to use a command like sleep, you can use -td and it will start a container and keep it running

$ docker ps
This command shows you all running containers on your host

$ docker stop <container_ID or NAMES>
This command allows you to stop an active container

$ docker ps -a
This shows you all containers on the host, even those in an Exited state

$ docker start <Container_ID or NAMES>
This will allow you to restart a container that is already in an Exited state

$ Docker rm <Container_ID or NAMES>
This command allows you to remove an exited container and reclaim the resources it is using. ***container must be stopped to remove***

$docker logs <Container_ID or NAMES>
Will show you the output from the logs to help in troubleshooting

$ docker rename <existing_name> <new_name>
This will allow you to rename the container

$ docker pause <container_ID or NAMES>
This will allow you to pause a running container

$ docker run -d –name <NAME> -p 8080:8080 -p5000:5000 jenkins:2.60.3
-d will have container deployed in detach mode allowing you to still use your terminal
–name will allow you to name your app
-p this is port mapping from container to host so we are exposing 8080 publicly, which will be confirmed when I put the host IP:8080 into a URL and let the prompt for my Jenkins credentials
jenkins:2.60.3 this applies the tag 2.60.3 which is the latest version of Jenkins in case a new update comes out tomorrow changing the latest version

Proof the above commands worked
Summary:
We covered a lot of base container commands here in this article. If you go out to docs.docker.com you will find plenty more to play with. As always, I hope y’all found this article helpful.