In this post, basically, I don't put options. If you think this command is lacking something important, you will need to check Docker Doc(https://docs.docker.com/)
pull
pull command is almost same as git pull. Get an image to local from Docker hub.
$ docker pull kojikno/conda_docker
push
push command is also the same as git push. This command uploads your Docker image to Docker Hub. This allows others to use your image or you can use the image from any machines. For example, you can use the image for CI. I'm using my own image for Circle CI to run the test.
The free plan allows us to have one private repo. You can make your image secure. The following: python3.7 is a tag. Generally, a community organization provides multiple versions of images.
For example, node:latest, node:11, node:10 etc.
$ docker push kojikno/conda_docker:python3.7
build
This command is to create an image from Dockerfile. You can see what Docker file is in the following post.
https://dev.to/kojikanao/learning-docker-002-images-5deb
ml_conda_docker
is an image name & tag.
$ docker build -t ml_conda_docker:latest .
images
This command shows you images you have. I think I have used this command so many times lol
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
arm64v8/ubuntu latest 56c6cce7dd32 7 days ago 57.7MB
circleci/picard latest 7d0931871af3 2 weeks ago 103MB
arm64v8/node 10.16.0-stretch 3583429b1ae9 3 weeks ago 853MB
rwmodel/runway/densedepth cpu 186943877dd5 8 weeks ago 1.85GB
rmi
This command is to remove an images. Sometimes images are huge, so need to delete images especially when I create an image from container which is based on an image from Docker Hub.
$ docker rmi image_id/image_name
$ docker rmi $(docker images -q --filter "dangling=true") <-- remove images which is named none
create
This command creates a container but doesn't start a container.
$ docker create image_name
run
This command is to run a container or start a container.
You should check the options.
https://docs.docker.com/engine/reference/run/
Also you can check my post about container(https://dev.to/kojikanao/learning-docker-001-containers-5ac6)
$ docker run -it image_name/image_id bash
ps
ps
could be your best friend when you use Docker.
This command shows you running containers' information. If you want to see stopped containers, you can add -a
.
$ docker ps
$ docker ps -a
commit
This command allows us to create an image from a container. We can pull an image and add/install anything we need then do commit
. After that, we can start run/create a container the image we committed.
One thing you should know is that commit
creates a new image from the image you pulled and the size of the new one could be bigger than the based one. So, you need care about your storage if you don't have enough storage on your machine.
$ docker commit container_id iamge_name:tag
start
This command is to start running a container.
$ docker start container_id/container_name
stop
This command is to stop a running container.
$ docker stop container_id/container_name
exit
When you are in Docker container, you can use exit
to get out there.
$ exit
attach
This command to attach local standard input, output, and error streams to a running container.
$ docker attach container_id/container_name
rm
This command deletes a container which is not running. You can remove multiple containers if you put multiple container_ids
$ docker rm container_id/container_name
# This commands remove all exited containers.
$ docker rm $(docker ps -qa --no-trunc --filter "status=exited")
+α
system prune
This command is to remove unused data.
If you really want to clean up your Docker environment, you can use -a
option. However, this option removes all unused data so be careful when you use this option.
$ docker system prune OPTIONS
exec
This command allows us to exec another process in a running container.
$ docker exec option container_id/container_name
Actually, there are so many commands you can use/should know, but I guess for a beginner like me these commands are kind of enough to learn the basics of Docker.
Hope this is useful for someone!
If something wrong or missing something important, please leave a comment!!!(I'm still learning Docker 😆)
Docker Doc
https://docs.docker.com/
Docker cheat sheet
https://github.com/wsargent/docker-cheat-sheet
If you don't like to use CLI, you can use Docker with GUI like kitematic(https://kitematic.com/), but probably CLI could be helpful to understand Docker since we will need to write Dockerfile, docker-compose.yml.
Top comments (14)
Brilliant. Definitely linking to this in a future article on containers, if that's cool.
Edit: Only thing I'd add would be
exec
. Folks who are getting into Docker likely have some experience on the command line, and being able to drop into a container's shell is hella helpful.yeah i typically use
docker exec -it container_id/container_name bash/sh
to get into existing, already running, containersThanks, Henry(@quinncuatro )!
I will add
exec
.I think the most user friendly and easiest to install GUI for managing docker is Portainer. Check it out if you want a quick GUI to manager everything in. Https://portainer.io
Can install it in two simple commands:
Linux Containers
Windows Containers
I think another useful command is docker system prune, especially for beginners in order to start with a fresh state and avoid version problems.
Thanks, Michael(@michael_wapp )!
I will add
docker system prune
Amazing article.
May I use your docker picture on my presentation for docker on Campus Party event (I will give credits and link your article)?
@rodrigondec , feel free to use it!
Very nice, I published a new article about Docker in my Medium blog. If you to access, link below:
medium.com/@amaurybsouza/docker-pa...
You forgot the most important one:
docker help
😉exit is not docker command. It is command of your OS shell running in container.
The picture is enough Internet for today :D
Love your illustration Koji! Please do another article on the commands in Dockerfile.
good blog,... thank for sharing <3