Docker – 如何设置镜像名称

huangapple go评论52阅读模式
英文:

Docker - how to set image name

问题

I have docker image which is created with docker-compose. There are 2 containers inside image. I need to change image name from 8_flask_nginx_docker to e.g. jodynek/flask-nginx:0.0.1.RELEASE. Is it possible inside docker-compose.yml? Thanks for help.

docker-compose.yml:

version: '3.9'  

services:
  web-app:
    image: jodynek/flask-nginx:0.0.1.RELEASE
    build: .
    command: python main.py
    volumes:
      - .:/code
    ports:
      - "3000:3000"

  nginx-proxy:
    image: nginx:alpine
    ports:
      - "8888:80"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
    depends_on:
      - web-app

Docker – 如何设置镜像名称

英文:

I have docker image which is created with docker-compose. There are 2 containers inside image. I need to change image name from 8_flask_nginx_docker to e.g. jodynek/flask-nginx:0.0.1.RELEASE. Is it possible inside docker-compose.yml? Thanks for help.

Docker – 如何设置镜像名称

docker-compose.yml:

version: '3.9'  

services:
  web-app:
    image: jodynek/flask-nginx:0.0.1.RELEASE
    build: .
    command: python main.py
    volumes:
      - .:/code
    ports:
      - "3000:3000"

  nginx-proxy:
    image: nginx:alpine
    ports:
      - "8888:80"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
    depends_on:
      - web-app

答案1

得分: 1

  • 项目名称是 my-project-name,你可以使用 -p 选项进行设置。
  • 如果你想设置自定义容器名称:
    • web-app 服务的容器名称是 my-web-container
    • nginx-proxy 服务的容器名称是 my-proxy
英文:

That's the project name and you can set it up with -p option.

docker compose -p my-project-name up.

If you want to set a custom container name:

services:
  web-app:
    container_name: my-web-container // <--- name here
    image: jodynek/flask-nginx:0.0.1.RELEASE
    build: .
    command: python main.py
    volumes:
      - .:/code
    ports:
      - "3000:3000"

  nginx-proxy:
    container_name: my-proxy // <-- name here
    image: nginx:alpine
    ports:
      - "8888:80"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
    depends_on:
      - web-app

huangapple
  • 本文由 发表于 2023年5月11日 02:39:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76221662.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定