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"
CodePudding user response:
As @votelessbubble mentioned, you can do docker-compose push
but only under certain conditions.
- You are pushing an image you have built locally
- which is in your case true for both images
- 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)
- now, this is where the problem lies. You need to have a private/public docker registry set in the
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.
If you are using a private repository, login to that repository first
docker login --username=<username> --email=<email> [SERVER]
Build the image
docker build -t <tag> .
# replace the dot with the current location of dockerfile or inside your projectPush the image
docker push <registry>/<user>/<service>:<tag>