Docker Command

Frequently used docker commands

Docker Quick Start

Create docker image from Dockerfile

1
2
3
4
5
6
7
8
9
# run the command in the folder which contains Dockerfile

# user@computer odoo_test % ls -la
# total 8
# drwxr-xr-x@ 3 user staff 96 Mar 6 09:42 .
# drwx------@ 20 user staff 640 Mar 7 01:42 ..
# -rw-r--r--@ 1 user staff 1546 Mar 6 09:42 Dockerfile

docker build -t salarymaster/odoo:odoo_12 .

Download docker image

1
2
# download from Docker Hub
docker pull salarymaster/odoo:H_12.0

Upload docker image

1
2
3
4
5
6
# upload to Docker Hub
docker push salarymaster/odoo:odoo_12

# "salarymaster" is the name of organization/user
# "odoo" is the repository name created by "salarymaster"
# "odoo_12" is the tag in "odoo" repository to distinguish different version of docker images

List docker image

1
docker image ls

Run docker image / Create image instance (container)

1
2
# this command will maintain the container even exiting
docker run -itu root salarymaster/odoo:basic /bin/bash

Tag docker image

1
2
# ImageID comes from "docker image ls" command
docker tag ImageID salarymaster/odoo:new_tagname

Remove docker image

1
2
3
4
5
# if ImageID is unique, use ImageID to remove
docker image rm ImageID

# if ImageID is not unique, use unique combination tag to remove
docker image rm OrgName/RepName:TagName

List docker container

1
2
3
4
5
# list using containers
docker ps

# list all the containers
docker ps -a

Start/Stop/Restart docker container

1
2
3
docker start ContainerID
docker stop ContainerID
docker restart ContainerID

Copy file using docker container

1
2
3
4
5
# copy file from container to local
docker cp ContainerID:/a/b/c.txt /aa/bb/

# copy file from local to container
docker cp /aa/bb/ ContainerID:/a/b/c.txt

Enter container

1
2
3
# -it use terminal to enter container
# -u use specific user to enter container
docker exec -itu root 1a9e7655efdc /bin/bash

‼️ Advanced

Inspect container

1
2
3
4
# check the container detail
docker inspect ContainerID
# or use this command to check docker log
docker inspect ContainerID | grep -i log

Debug dead container

1
2
# copy file from container to local
docker cp ContainerID:/a/b/c.txt /aa/bb/

Check container start command