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.
My question is:
Since this has multiple images within the container:
- would each image be a different repository on docker hub or
- would it be in the same repository, but with different tags such as :web or :nginx?
Here is my docker-compose.yml:
JavaScript
x
39
39
1
version: '3.7'
2
3
services:
4
web:
5
build:
6
context: ./app
7
dockerfile: Dockerfile.prod
8
command: gunicorn ether.wsgi:application --bind 0.0.0.0:8000
9
volumes:
10
- static_volume:/home/app/web/staticfiles
11
- media_volume:/home/app/web/media
12
expose:
13
- 8000
14
env_file:
15
- ./.env.prod
16
depends_on:
17
- db
18
db:
19
image: postgres:12.0-alpine
20
volumes:
21
- postgres_data:/var/lib/postgresql/data/
22
env_file:
23
- ./.env.prod.db
24
nginx:
25
build: ./nginx
26
volumes:
27
- static_volume:/home/app/web/staticfiles
28
- media_volume:/home/app/web/media
29
ports:
30
- 1337:80
31
depends_on:
32
- web
33
34
volumes:
35
postgres_data:
36
static_volume:
37
media_volume:
38
39
and
Dockerfile
JavaScript
1
70
70
1
###########
2
# BUILDER #
3
###########
4
5
# pull official base image
6
FROM python:3.8.3-alpine as builder
7
8
# set work directory
9
WORKDIR /usr/src/app
10
11
# set environment variables
12
ENV PYTHONDONTWRITEBYTECODE 1
13
ENV PYTHONUNBUFFERED 1
14
15
# install psycopg2 dependencies
16
RUN apk update
17
&& apk add postgresql-dev gcc python3-dev musl-dev
18
19
# lint
20
RUN pip install --upgrade pip
21
COPY . .
22
23
# install dependencies
24
COPY ./requirements.txt .
25
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt
26
27
28
#########
29
# FINAL #
30
#########
31
32
# pull official base image
33
FROM python:3.8.3-alpine
34
35
# create directory for the app user
36
RUN mkdir -p /home/app
37
38
# create the app user
39
RUN addgroup -S app && adduser -S app -G app
40
41
# create the appropriate directories
42
ENV HOME=/home/app
43
ENV APP_HOME=/home/app/web
44
RUN mkdir $APP_HOME
45
RUN mkdir $APP_HOME/staticfiles
46
RUN mkdir $APP_HOME/media
47
WORKDIR $APP_HOME
48
49
# install dependencies
50
RUN apk update && apk add libpq
51
COPY --from=builder /usr/src/app/wheels /wheels
52
COPY --from=builder /usr/src/app/requirements.txt .
53
RUN pip install --no-cache /wheels/*
54
55
# copy entrypoint-prod.sh
56
COPY ./entrypoint.prod.sh $APP_HOME
57
58
# copy project
59
COPY . $APP_HOME
60
61
# chown all the files to the app user
62
RUN chown -R app:app $APP_HOME
63
64
# change to the app user
65
USER app
66
67
# run entrypoint.prod.sh
68
ENTRYPOINT ["/home/app/web/entrypoint.prod.sh"]
69
70
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