cloudscode / ToDo

0 stars 0 forks source link

Learing Docker #4

Open cloudscode opened 7 years ago

cloudscode commented 7 years ago

Learing Docker

cloudscode commented 7 years ago
cloudscode commented 7 years ago

View docker images

docker images

delete docker images

docker rmi -f [IMAGE ID]

View the running docker

docker ps

View all docker

docker ps -a

delete all docker

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

cloudscode commented 7 years ago

build docker

docker build -t pft/centos:7.1 .
cloudscode commented 7 years ago

start docker

docker start dockerId

stop docker

docker stop dockerId
cloudscode commented 7 years ago

registry

docker run -d -p 5000:5000 --name registry registry

#

docker run -d -v /opt/registry:/var/lib/registry -p 5000:5000 --restart=always --name registry registry

push

docker push 192.168.1.128:5000/test/jdk:1.8

cloudscode commented 7 years ago

docker commit image

docker commit oldimage mynewimage
cloudscode commented 7 years ago

view docker container image info

docker inspect imageId
cloudscode commented 7 years ago

docker export

docker export 634bb > centosposeidon.tar

docker import

cat centosposeidon.tar | sudo docker import - pft/centosposeidon:v1.0

docker import from url

sudo docker import http://viabugs.com/centosposeidon.tgz pft/centosposeidon:v1.0
cloudscode commented 7 years ago

docker-compose

docker-compose -v

启动多个容器

docker-compose up
docker-compose up -d

停止

docker-compose stop

查看

docker-compose ps
docker-compose ps -a

删除

docker-compose rm
cloudscode commented 7 years ago

退出容器

  1. 不要用ctrl+c,ctrl+c是让docker容器停止了。

  2. 用如下快捷键:先按:ctrl+p;再按:ctrl+q。

cloudscode commented 7 years ago

dockerfile VOLUME

VOLUME 指令创建的挂载点,无法指定主机上对应的目录,对应目录是自动生成的,用命令查看docker inspect。

VOLUME ["/var/jetty/pft/web/logs"]

docker inspect

通过docker inspect 查看通过该dockerfile创建的镜像生成的容器,通过Mounts属性看挂载点的信息。

"Mounts": [          
            {
                "Type": "volume",
                "Name": "0314887f053cfa6fa7ab78880493135fb91ce6c79644b37651b15b168bed387c",
                "Source": "/var/lib/docker/volumes/0314887f053cfa6fa7ab78880493135fb91ce6c79644b37651b15b168bed387c/_data",
                "Destination": "/var/jetty/pft/web/logs",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            }
        ]
cloudscode commented 7 years ago

深入浅出Docker

Docker命令行探秘

Centos Docker1.12 远程Rest api访问的配置方法

http://www.cnblogs.com/suredandan/p/6559113.html http://www.cnblogs.com/zhangmingcheng/p/6587020.html

vi /lib/systemd/system/docker.service
ExecStart=/usr/bin/docker daemon --tls=false -H unix:///var/run/docker.sock -H tcp://192.168.20.250:4243
systemctl daemon-reload && systemctl restart docker
curl http://192.168.20.250:4243/v1.24/info
cloudscode commented 7 years ago

restart 重启一个容器或多个容器

Usage: docker restart [OPTIONS] CONTAINER [CONTAINER...]Restart a running container
cloudscode commented 6 years ago

宿主机同步文件到容器

docker cp /var/java/apache-maven-3.3.9.7z 90a9b5b2405d:/usr/local/package

cloudscode commented 6 years ago

bash in docker

docker exec -it {容器id} bash