Skip to content
Advertisement

docker hub do you create a repository for every image

I am new to docker and docker hub. I am trying to understand the repository on docker hub. I have dockerized a django web app using nginx and gunicorn. enter image description here My question is: Since this has multiple images within the container:

  1. would each image be a different repository on docker hub or
  2. would it be in the same repository, but with different tags such as :web or :nginx?

Here is my docker-compose.yml:

version: '3.7'

services:
web:
 build:
   context: ./app
   dockerfile: Dockerfile.prod
 command: gunicorn ether.wsgi:application --bind 0.0.0.0:8000
 volumes:
   - static_volume:/home/app/web/staticfiles
   - media_volume:/home/app/web/media
 expose:
   - 8000
 env_file:
   - ./.env.prod
 depends_on:
   - db
db:
 image: postgres:12.0-alpine
 volumes:
   - postgres_data:/var/lib/postgresql/data/
 env_file:
   - ./.env.prod.db
nginx:
 build: ./nginx
 volumes:
   - static_volume:/home/app/web/staticfiles
   - media_volume:/home/app/web/media
 ports:
   - 1337:80
 depends_on:
   - web

volumes:
postgres_data:
static_volume:
media_volume:

and

Dockerfile

###########
# BUILDER #
###########

# pull official base image
FROM python:3.8.3-alpine as builder

# set work directory
WORKDIR /usr/src/app

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# install psycopg2 dependencies
RUN apk update 
    && apk add postgresql-dev gcc python3-dev musl-dev

# lint
RUN pip install --upgrade pip
COPY . .

# install dependencies
COPY ./requirements.txt .
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt


#########
# FINAL #
#########

# pull official base image
FROM python:3.8.3-alpine

# create directory for the app user
RUN mkdir -p /home/app

# create the app user
RUN addgroup -S app && adduser -S app -G app

# create the appropriate directories
ENV HOME=/home/app
ENV APP_HOME=/home/app/web
RUN mkdir $APP_HOME
RUN mkdir $APP_HOME/staticfiles
RUN mkdir $APP_HOME/media
WORKDIR $APP_HOME

# install dependencies
RUN apk update && apk add libpq
COPY --from=builder /usr/src/app/wheels /wheels
COPY --from=builder /usr/src/app/requirements.txt .
RUN pip install --no-cache /wheels/*

# copy entrypoint-prod.sh
COPY ./entrypoint.prod.sh $APP_HOME

# copy project
COPY . $APP_HOME

# chown all the files to the app user
RUN chown -R app:app $APP_HOME

# change to the app user
USER app

# run entrypoint.prod.sh
ENTRYPOINT ["/home/app/web/entrypoint.prod.sh"]

Advertisement

Answer

Generally, tags represent different versions of the same base container or application.

Therefore, it’s recommended to have separate repositories for the static assets (nginx) and the backend api (your web image), however this isn’t a hard rule. You could just as easily do app:v1-nginx and app:v1-api, but the API will likely be tagged and pushed more often than the other, so the version numbers wouldn’t necessarily be aligned

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement