The most popular Docker commands

  Oct 10, 2017      2m      0   

A collection of popular commands for Docker;run and stop Docker container; build Docker image; remove Docker images; import and export docker images.

The most popular Docker commands

The Docker commands that I use mostly. It worths listing all the essential commands.

Popular Docker commands

Standard Docker run

$ docker run --name `containerName` -p hostPort:appPortInDocker -e KEY=VALUE -t repo:tag

Standard Docker build

$ docker build -t repo:tag .  
# (the `dot` at the last command means build the `Dockerfile` file in the current directory)

Stop the container

$ docker stop `containerName`

Start the container later

$ docker start `containerName`

View running containers

$ docker ps

View all images

$ docker images

View docker container in details

$ docker inspect ID-or-NAME (eg. $ docker inspect 62a932a5c143)

Remove all containers

$ docker rm $(docker ps -a -q)

Remove all images

$ docker rmi $(docker images -q)

Remove unused Docker images

$ docker rmi -f $(docker images | grep "<none>" | awk "{print \$3}")

Run docker without sudo

$ sudo addgroup -a $(whoami) docker

Run docker in interactive mode

$ docker run -it --rm busybox:latest  
* `busybox` is the image name
* `latest` is the version

Detaching containers without stopping them

Press Ctrl-P and then Ctrl-Q to detach.

Save Docker image

# or running Docker containers, first create a new image from a container’s changes.
$ docker commit --change "Added something" webapp webapp:v2

$ docker save rook/ceph:master > rook-ceph.tar

Load Docker image

$ docker load < rook-ceph.tar


$ docker load -i rook-ceph.tar

Docker-compose commands

Run docker compose

$ docker-compose up  
$ docker-compose up -d (detached mode)  
$ docker-compose `--file my_docker_compose_file.yml` up -d (if you want to run specific docker-compose file)  

Restart a running container started by docker-compose

$ docker-compose restart

Stop a running container started by docker-compose

$ docker-compose stop


Khám phá xử lý ảnh - GVGroup