参见:https://docs.docker.com/docker-for-mac/install/
docker run -d -p 5000:5000 registry
# 其他示例,运行node
docker run -itd --name node-anyproxy -p 8003:8003 -p 8002:8002 node
修改 docker 的配置,增加图中的那一段,才可以不使用证书上传,内网的服务建议使用:
docker run hello-world
docker tag hello-world 192.168.2.226:5000/myword:latest
docker push 192.168.2.226:5000/myword:latest
curl http://<ip>:5000/v2/_catalog
可能碰到的问题,
容器,镜像,仓库
yum check-update
curl -fsSL https://get.docker.com/ | sh
systemctl start docker
systemctl status docker
systemctl enable docker
# 这里的版本号可以改成github中release页面中最新的版本号
curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
# 这里的版本号可以改成github中release页面中最新的版本号
curl -L https://github.com/docker/machine/releases/download/v0.14.0/docker-machine-`uname -s`-`uname -m` >/tmp/docker-machine
chmod +x /tmp/docker-machine
cp /tmp/docker-machine /usr/local/bin/docker-machine
docker pull <REPOSITORY name>
# 查看镜像列表
docker images
# 查看没有tag的镜像
docker image ls --filter dangling=true
# 查看某镜像详情
docker inspect <IMAGE ID>
# 以下两条命令结果相同
docker inspect ubuntu:latest
docker image inspect ubuntu:latest
docker container inspect
docker search <TERM>
# 支持参数:
# --automated=false,仅显示自动创建的镜像
# --no-trunc=false,输出信息不截断显示
# -s,--stars=0,指定仅显示评价为指定星级以上的镜像
docker search alpine --filter "is-official=true"
docker search alpine --filter "is-automated=true"
docker rmi <IMAGE>
# 可使用标签或镜像id,删除镜像前,一般需要删除使用该镜像的容器
docker image rm 02674b9cb179
# 删除所有镜像
docker image rm $(docker image ls -q) -f
shell
docker commit
# -a, author
# -m, message
# -p, pause,提交时暂停容器运行
docker push
# 上传到 DockerHub,需要用户名和密码
start, run, stop
docker create -it ubuntu:latest
#查看本机所有容器
docker start
docker run
docker restart
docker start percy
docker container run --rm golang go version
docker container run -it ubuntu:latest /bin/bash
docker container exec -it 3027eb644874 bash
docker container run --name percy -it ubuntu:latest /bin/bash
# always stop后会立即重启,且重启docker服务后,会重启该容器
# unless-stopped stop后会立即重启,但重启docker服务后不会重启
# on-failed
docker container run --name neversaydie -it --restart always alpine sh
docker ps -a
#查看本机所有容器
# 首先执行 docker container ps -a 来查看本地有哪些容器
# 通过 容器id => 第1列 或 容器名 => 最后一列 启动容器
docker start [containerId / name]
docker rm
docker stop 975b5ca0eba7
docker container stop 975b5ca0eba7
docker container stop percy
docker logs -f container_id
docker exec
# 示例
docker exec -it node-anyproxy /bin/bash
docker export
docker import
-p 指定端口
-P 随机端口
FROM
FROM alpine
MAINTAINER
LABEL maintainer="nigelpoulton@hotmail.com"
RUN
RUN apk add --update nodejs nodejs-npm
RUN npm install
CMD
ENV
ADD
COPY
COPY . /src
EXPOSE
EXPOSE 8080
ENTRYPOINT
ENTRYPOINT ["node", "./app.js"]
VOLUMN
USER
WORKDIR
WORKDIR /src
ONBUILD
FROM node:latest AS storefront
WORKDIR /usr/src/atsea/app/react-app
COPY react-app .
RUN npm install
RUN npm run build
FROM maven:latest AS appserver
WORKDIR /usr/src/atsea
COPY pom.xml .
RUN mvn -B -f pom.xml -s /usr/share/maven/ref/settings-docker.xml dependency\
:resolve
COPY . .
RUN mvn -B -s /usr/share/maven/ref/settings-docker.xml package -DskipTests
FROM java:8-jdk-alpine AS production
RUN adduser -Dh /home/gordon gordon
WORKDIR /static
COPY --from=storefront /usr/src/atsea/app/react-app/build/ .
WORKDIR /app
COPY --from=appserver /usr/src/atsea/target/AtSea-0.0.1-SNAPSHOT.jar .
ENTRYPOINT ["java", "-jar", "/app/AtSea-0.0.1-SNAPSHOT.jar"]
CMD ["--spring.profiles.active=postgres"]
docker network ls
docker network create -d bridge localnet
brctl show
docker container run -d --name c1 --network localnet alpine sleep 1d
docker network inspect localnet --format '{{json .Containers}}'
# Deletes all unused networks on a Docker host.
docker network prune
docker volume ls
docker volume create myvol
docker volume inspect myvol
ocker volume prune
# this command will create volume: bizvol, even though it does not exist
docker container run -dit --name voltainer --mount source=bizvol,target=/vol alpine
# docker-compose命令需要在有docker-compose.yml的目录执行
docker-compose up
docker-compose -f prod-equus-bass.yml up
# 将恢复到执行docker-compose up之前的状态
docker-compose down
docker-compose ps
docker-compose top
# 仅停止容器,network, volume仍然存活
docker-compose stop
# 仅重启容器
docker-compose restart
# demo
git clone https://github.com/nigelpoulton/counter-app.git
# volume location:
/var/lib/docker/volumes/counterapp_counter-vol
docker swarm init --advertise-addr 10.0.0.1:2377 --listen-addr 10.0.0.1:2377
docker node ls
docker swarm join-token worker
docker swarm join-token manager
docker swarm join --token SWMTKN-1-0uahebax...c87tu8dx2c 10.0.0.1:2377 --advertise-addr 10.0.0.4:2377 --listen-addr 10.0.0.4:2377
docker service create
# web-fe是name
docker service inspect --pretty web-fe
docker service ps web-fe
docker service inspect --pretty web-fe
# Scaling a service(缩放服务)
docker service scale web-fe=10
docker service rm web-fe
# Rolling updates
docker network create -d overlay uber-net
# troubleshooting
docker service logs seastack_reverse_proxy
git clone https://github.com/dockersamples/atsea-sample-shop-app.git
docker stack deploy -c docker-stack.yml seastack
docker stack ps seastack
docker service logs seastack_reverse_proxy
# update the docker-stack.yml file then deploy again
docker stack deploy -c docker-stack.yml seastack
docker stack rm seastack
docker search nginx
docker run --name nginx -p 7000:7000 -v /Users/chencarl/Downloads/workspace/docker-files/nginx/logs/:/var/log/nginx -v /Users/chencarl/Downloads/workspace/docker-files/nginx/html:/usr/share/nginx/html -v /Users/chencarl/Downloads/workspace/docker-files/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:ro -v -d nginx