Docker Commands
docker search [OPTIONS] TERM
docker pull [OPTIONS] IMAGE[:TAG]
docker push [OPTIONS] NAME[:TAG]
docker login/logout [OPTIONS] [SERVER]
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
docker start/stop/restart CONTAINER
-d
,-i
,-t
】docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
docker top [OPTIONS] CONTAINER [ps OPTIONS]
-m
, -a
, tag
缺省】docker commit -m "change sth" -a "somebody" CONTAINER IMAGE:TAG
docker ps
docker ps -l
docker ps -a
docker inspect CONTAINER
ctrl + d
或 exit
ctrl + p + q
docker rm $(docker ps -qf status=exited)
docker container prune
docker pull redis
[root@VM_32_161_centos ~]# docker run -d -p 6379:6379 docker.io/redis:latest
ecdedee43022066baf04592b7749397c4bb383f92ac0080efe40f7a978493858
[root@VM_32_161_centos ~]# docker inspect ecde
[
{
"Id": "ecdedee43022066baf04592b7749397c4bb383f92ac0080efe40f7a978493858",
"Created": "2019-04-17T06:33:57.453089857Z",
"Path": "docker-entrypoint.sh",
"Args": [
"redis-server"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 10326,
"ExitCode": 0,
"Error": "",
"StartedAt": "2019-04-17T06:33:57.664264501Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:a55fbf438dfd878424c402e365ef3d80c634f07d0f5832193880ee1b95626e4e",
"ResolvConfPath": "/var/lib/docker/containers/ecdedee43022066baf04592b7749397c4bb383f92ac0080efe40f7a9784 93858/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/ecdedee43022066baf04592b7749397c4bb383f92ac0080efe40f7a978493 858/hostname",
"HostsPath": "/var/lib/docker/containers/ecdedee43022066baf04592b7749397c4bb383f92ac0080efe40f7a978493858 /hosts",
"LogPath": "/var/lib/docker/containers/ecdedee43022066baf04592b7749397c4bb383f92ac0080efe40f7a978493858/e cdedee43022066baf04592b7749397c4bb383f92ac0080efe40f7a978493858-json.log",
"Name": "/elegant_bardeen",
"RestartCount": 0,
"Driver": "overlay2",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
......
docker pull centos
docker run -it centos
docker run -d centos /bin/bash -c "echo hello world"
或
docker run -d centos echo "hello world"
docker run -d centos python /root/app.py
docker logs container_id
docker commit -m "change sth" -a "somebody" container_id image_name
docker pull python:3.6.8
docker run -v /root/src:/usr/local/src python:3.6.8 python /usr/local/src/app.py
docker run python:3.6.8 pip list
# 引用 python:3.6.8镜像,直接安装在生成的新镜像内
FROM python:3.6.8
MAINTAINER cn.Dixon
MAINTAINER [email protected]
# 工作目录
WORKDIR /root/
# 将宿主机当前路径下的.ssh文件夹复制到容器内部/root/.ssh
COPY .ssh/ /root/.ssh/
# git克隆项目
RUN apt-get install git ; git clone [email protected]:dmp/xxx.git
# 镜像启动命令,通常为项目启动命令
CMD /bin/sh
[root@VM_32_161_centos ~]# docker build -f Dockerfile -t IMAGE:TAG .
Sending build context to Docker daemon 343.6 kB
Step 1/7 : FROM python:3.6.8
---> d2f1c567199a
Step 2/7 : MAINTAINER cn.Dixon
---> Using cache
---> fcd79cf4fd4b
Step 3/7 : MAINTAINER [email protected]
---> Using cache
---> 3c2ed9f2186e
Step 4/7 : WORKDIR /root/
---> Using cache
---> 8a73dcd920f3
Step 5/7 : COPY .ssh/ /root/.ssh/
---> 9111eb8786e8
Removing intermediate container 7363dd035ee1
Step 6/7 : RUN apt-get install git ; git clone [email protected]:dmp/xxx.git
---> Running in 603e84afaf74
Reading package lists...
Building dependency tree...
Reading state information...
git is already the newest version (1:2.11.0-3+deb9u4).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Cloning into 'xxx'...
---> 8de54af9e744
Removing intermediate container 603e84afaf74
Step 7/7 : CMD /bin/sh
---> Running in b4ffc5f157e8
---> 5786d0622e6a
Removing intermediate container b4ffc5f157e8
Successfully built 5786d0622e6a
# 调用原 Dockerfile 中的 CMD 命令
docker run IMAGE[:TAG]
# 调用容器内 python 解释器执行容器内代码
docker run IMAGE[:TAG] python xxx/xxx.py
# 指定工作目录,更新 git 项目
docker run -w /root/xxx IMAGE[:TAG] git pull