Docker常用命令备忘录

docker build构建镜像

bash
docker build -f Dockerfile -t t:0.1 .
docker build -f Dockerfile -t t:0.1 .

查看镜像及image id

bash
docker images
docker images

关联image id和远端的image name

bash
# 后面的远端镜像image名改成你自己的,绑定本地镜像tag和远端镜像tag的关联关系
docker tag <image id> yakima/semantic-segmentation-editor:0.1
# 后面的远端镜像image名改成你自己的,绑定本地镜像tag和远端镜像tag的关联关系
docker tag <image id> yakima/semantic-segmentation-editor:0.1

上传镜像

bash
# 上传镜像(将push后面跟的镜像tag换成你自己的)
sudo docker push yakima/semantic-segmentation-editor:0.1
# 上传镜像(将push后面跟的镜像tag换成你自己的)
sudo docker push yakima/semantic-segmentation-editor:0.1

登录docker

bash
docker login
docker login

然后根据提示输入用户名(不是邮箱)和密码,回车。

docker compose运行服务

bash
# 重点是传入.yml文件路径
docker-compose -f sse-docker-stack.yml up

# 举例:前面的示例如何传递环境变量,重要的是后面传入.yml文件路径的地方
METEOR_SETTINGS=$(cat ../path/<semantic-segmentation-editor>/settings.json) SSE_IMAGES=/Users/<username>/sse-images docker-compose -f sse-docker-stack.yml up
# 重点是传入.yml文件路径
docker-compose -f sse-docker-stack.yml up

# 举例:前面的示例如何传递环境变量,重要的是后面传入.yml文件路径的地方
METEOR_SETTINGS=$(cat ../path/<semantic-segmentation-editor>/settings.json) SSE_IMAGES=/Users/<username>/sse-images docker-compose -f sse-docker-stack.yml up

yml文件内容示例:

yml
version: '3'

services:
  app:
    image: yakima/semantic-segmentation-editor:0.1
    volumes:
      - "${SSE_IMAGES}:/root/sse-images:rw"
    ports:
      - '80:3000'
    depends_on:
      - mongo
    environment:
      ROOT_URL: ${APP_ROOT_URL:-http://localhost}
      MONGO_URL: mongodb://mongo:27017/meteor
      PORT: 3000
      METEOR_SETTINGS: ${METEOR_SETTINGS}

  mongo:
    image: mongo:latest
    command:
      - --storageEngine=wiredTiger
    volumes:
      - data:/data/db

volumes:
  data:
version: '3'

services:
  app:
    image: yakima/semantic-segmentation-editor:0.1
    volumes:
      - "${SSE_IMAGES}:/root/sse-images:rw"
    ports:
      - '80:3000'
    depends_on:
      - mongo
    environment:
      ROOT_URL: ${APP_ROOT_URL:-http://localhost}
      MONGO_URL: mongodb://mongo:27017/meteor
      PORT: 3000
      METEOR_SETTINGS: ${METEOR_SETTINGS}

  mongo:
    image: mongo:latest
    command:
      - --storageEngine=wiredTiger
    volumes:
      - data:/data/db

volumes:
  data:

进入docker镜像

bash
docker run -it yakima/semantic-segmentation-editor:0.1 bash
docker run -it yakima/semantic-segmentation-editor:0.1 bash

说明:进入镜像后,执行exit退出镜像。