docker login [OPTIONS] [SERVER]
1
2
|
docker login
docker login registry.gitlab.com
|
docker pull [OPTIONS] NAME[:TAG|@DIGEST]
1
2
3
4
|
docker pull gitlab/gitlab-ce:latest
docker pull php:7.2
docker pull mysql:5.6
docker pull registry.gitlab.com/scottchayaa/laravel-ci:latest
|
docker build [OPTIONS] PATH | URL | -
1
|
docker build -t example:latest .
|
How to use –build-arg in Dockerfile
1
2
3
|
docker build \
--build-arg TMP_DIR=tmp_example1 \
-t example:latest .
|
Dockerfile
1
2
3
4
5
6
7
|
From php:7.1
ARG TMP_DIR
ADD ./${TMP_DIR:tmp_example} /tmp/
RUN ln -s /tmp/${TMP_DIR}
CMD echo Hello world
# ${TMP_DIR:tmp_example} => default value is "tmp_example"
|
docker rm [OPTIONS] CONTAINER [CONTAINER…]
1
2
3
4
5
6
7
8
9
10
11
12
|
# Remove container which name is gitlab
docker rm gitlab
# Remove container which status is exited
docker rm $(docker ps -q -f status=exited)
# Remove all stopped containers
docker rm $(docker ps -a -q)
# Remove a container and its volumes
docker rm -v redis
redis
|
docker rmi [OPTIONS] IMAGE [IMAGE…]
1
2
3
4
5
|
# Remove image id = fd484f19954f
docker rmi -f fd484f19954f
# Remove image tag = <none> (safe)
docker rmi $(docker images --filter "dangling=true" -q --no-trunc)
|
docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG…]
Important Options :
Name, shorthand |
Description |
–publish , -p |
Publish a container’s port(s) to the host |
–privileged |
container內的root擁有真正的root權限 |
–name |
Assign a name to the container |
–volume , -v |
Bind mount a volume |
–detach , -d |
Run container in background and print container ID |
–cpus |
Number of CPUs, ex: 0.3, 1, 2.5… |
–restart |
Restart policy to apply when a container exits, ex: no(default) , always : Restart policies |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# run php
docker run -dit --name php php:7.1
# run gitlab
docker run --detach \
--hostname gitlab.example.com \
--publish 443:443 --publish 80:80 --publish 22:22 \
--name gitlab \
--restart always \
--volume /srv/gitlab/config:/etc/gitlab \
--volume /srv/gitlab/logs:/var/log/gitlab \
--volume /srv/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:latest
# run example on windows
docker run --detach ^
--hostname gitlab.example.com ^
--publish 28443:443 --publish 28080:80 --publish 28022:22 ^
--name gitlab ^
--restart always ^
--volume D:/Docker/gitlab-ce_latest/config:/etc/gitlab ^
--volume D:/Docker/gitlab-ce_latest/logs:/var/log/gitlab ^
--volume D:/Docker/gitlab-ce_latest/data:/var/opt/gitlab ^
gitlab/gitlab-ce:latest
|
docker exec [OPTIONS] CONTAINER COMMAND [ARG…]
1
|
docker exec -it php /bin/bash
|
Display the running processes of a container
docker top CONTAINER
docker stats [OPTIONS] [CONTAINER…]
1
2
3
4
5
6
7
|
$ docker stats
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
b95a83497c91 awesome_brattain 0.28% 5.629MiB / 1.952GiB 0.28% 916B / 0B 147kB / 0B 9
67b2525d8ad1 foobar 0.00% 1.727MiB / 1.952GiB 0.09% 2.48kB / 0B 4.11MB / 0B 2
e5c383697914 test-1951.1.kay7x1lh1twk9c0oig50sd5tr 0.00% 196KiB / 1.952GiB 0.01% 71.2kB / 0B 770kB / 0B 1
4bda148efbc0 random.1.vnc8on831idyr42slu578u3cr 0.00% 1.672MiB / 1.952GiB 0.08%
|
Reference