简体   繁体   中英

How to push to the hub a docker container with two images made by docker-compose?

I have 2 docker images, one for flask BE and another for React FE. I created a docker-compose and everything goes ok. I need to push this... container?, composer? to docker hub, how can i do this? I add to this post both dockerfiles and the docker-compose.yml file.

BackEnd

FROM python:3.9.0

WORKDIR /app

COPY ./requirements.txt .

RUN pip install -r requirements.txt

COPY . .

RUN python -m nltk.downloader all

EXPOSE 5000

CMD ["gunicorn", "-b", "0.0.0.0:5000", "app:app"]

FrontEnd

FROM node:16-alpine

RUN mkdir -p /app

WORKDIR /app

COPY ./package*.json ./

RUN npm install

COPY . .

EXPOSE 3000

CMD ["npm", "run", "start"]

docker-composer.yml

services:
  api:
    build:
      context: .
      dockerfile: Dockerfile
    image: flask-back
    ports:
      - "5000:5000"
  client:
    build:
      context: .
      dockerfile: Dockerfile
    image: react-front
    ports:
      - "3000:3000"

As @votelessbubble mentioned, you can do docker-compose push but only under certain conditions.

  1. You are pushing an image you have built locally
    • which is in your case true for both images
  2. You have access to the build key
    • now, this is where the problem lies. You need to have a private/public docker registry set in the image section as show in the yaml below ( link to documentation )
services:
  service1:
    build: .
    image: localhost:5000/yourimage  ## goes to local registry

  service2:
    build: .
    image: your-dockerid/yourimage  ## goes to your repository on Docker Hub

What I suggest to do, is to push these images not with the docker-compose push command, but rather with docker push . The steps you need to take are following.

  1. If you are using a private repository, login to that repository first

    docker login --username=<username> --email=<email> [SERVER]

  2. Build the image

    docker build -t <tag>. # replace the dot with the current location of dockerfile or inside your project

  3. Push the image

    docker push <registry>/<user>/<service>:<tag>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM