Dockerfile-dev против Dockerdev-prod - PullRequest
       82

Dockerfile-dev против Dockerdev-prod

0 голосов
/ 21 февраля 2019

Это моя структура проекта Docker:

├── docker-compose-dev.yml
├── docker-compose-prod.yml
└── services
    ├── client
    │   ├── Dockerfile-dev
    │   ├── Dockerfile-prod
    ├── nginx
    │   ├── Dockerfile-dev
    │   ├── Dockerfile-prod
    │   ├── dev.conf
    │   └── prod.conf
    └── web
        ├── Dockerfile-dev   <----- THIS
        ├── Dockerfile-prod  <----- THIS
        ├── entrypoint-prod.sh
        ├── entrypoint.sh
        ├── htmlcov
        ├── manage.py
        ├── project
        │   ├── __init__.py
        │   ├── api
        │   │   ├── __init__.py
        │   │   ├── models.py
        │   │   ├── templates
        │   │   │   └── index.html
        │   │   └── users.py
        │   ├── config.py
        │   ├── db
        │   │   ├── Dockerfile
        │   │   └── create.sql
        └── requirements.txt

На этапе разработки docker images для моего проекта было успешно создано с помощью:

$ docker-compose -f docker-compose-dev.yml up --build

Dockerfile-dev в веб-сервисе

# base image
FROM python:3.6-alpine

# install dependencies
RUN apk update && \
    apk add --virtual build-deps gcc python-dev musl-dev && \
    apk add libffi-dev && \
    apk add postgresql-dev && \
    apk add netcat-openbsd && \
    apk add bind-tools && \
    apk add --update --no-cache g++ libxslt-dev && \
    apk add jpeg-dev zlib-dev

ENV PACKAGES="\
    dumb-init \
    musl \
    libc6-compat \
    linux-headers \
    build-base \
    bash \
    git \
    ca-certificates \
    freetype \
    libgfortran \
    libgcc \
    libstdc++ \
    openblas \
    tcl \
    tk \
    libssl1.0 \
    "
ENV PYTHON_PACKAGES="\
    numpy \
    matplotlib \
    scipy \
    scikit-learn \
    nltk \
    "   
RUN apk add --no-cache --virtual build-dependencies python3 \
    && apk add --virtual build-runtime \
    build-base python3-dev openblas-dev freetype-dev pkgconfig gfortran \
    && ln -s /usr/include/locale.h /usr/include/xlocale.h \
    && python3 -m ensurepip \
    && rm -r /usr/lib/python*/ensurepip \
    && pip3 install --upgrade pip setuptools \
    && ln -sf /usr/bin/python3 /usr/bin/python \
    && ln -sf pip3 /usr/bin/pip \
    && rm -r /root/.cache \
    && pip install --no-cache-dir $PYTHON_PACKAGES \
    && pip3 install 'pandas<0.21.0' \
    && apk del build-runtime \
    && apk add --no-cache --virtual build-dependencies $PACKAGES \
    && rm -rf /var/cache/apk/*

# set working directory
WORKDIR /usr/src/app

# add and install requirements
COPY ./requirements.txt /usr/src/app/requirements.txt
RUN pip install -r requirements.txt

# add entrypoint.sh
COPY ./entrypoint.sh /usr/src/app/entrypoint.sh

RUN chmod +x /usr/src/app/entrypoint.sh

# add app
COPY . /usr/src/app

# run server
CMD ["/usr/src/app/entrypoint.sh"]

docker ps -as показывает, что проект запущен и работает на localhost:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                    PORTS                    NAMES               SIZE
f88c27e5334f        dev3_nginx          "nginx -g 'daemon of…"   14 hours ago        Up 14 hours               0.0.0.0:80->80/tcp       dev3_nginx_1        2B (virtual 16.1MB)
f77eb7949fef        dev3_client         "npm start"              14 hours ago        Up 14 hours               0.0.0.0:3007->3000/tcp   dev3_client_1       55B (virtual 553MB)
33b1b50931a6        dev3_web            "/usr/src/app/entryp…"   14 hours ago        Up 14 hours               0.0.0.0:5001->5000/tcp   dev3_web_1          35.3kB (virtual 3.32GB)
0e28363ab85a        dev3_web-db         "docker-entrypoint.s…"   3 days ago          Up 14 hours               0.0.0.0:5435->5432/tcp   dev3_web-db_1       63B (virtual 71.7MB)

Но я не могу собрать свои производственные образы с помощью:

$ docker-compose -f docker-compose-prod.yml up --build

Dockerfile-prod в веб-сервисе

(...the same as Dockerfile-dev from top to here)

# set working directory
WORKDIR /usr/src/app

# add and install requirements
COPY ./requirements.txt /usr/src/app/requirements.txt
RUN pip install -r requirements.txt

# new
# add entrypoint.sh
COPY ./entrypoint.sh /usr/src/app/entrypoint-prod.sh
RUN chmod +x /usr/src/app/entrypoint-prod.sh

# add app
COPY . /usr/src/app

# new
# run server
CMD ["/usr/src/app/entrypoint-prod.sh"]

при зависании производственной сборкипосле установки numpy, и она никогда не разрешается.

(...)
Collecting pip
  Downloading https://files.pythonhosted.org/packages/d8/f3/413bab4ff08e1fc4828dfc59996d721917df8e8583ea85385d51125dceff/pip-19.0.3-py2.py3-none-any.whl (1.4MB)
Requirement already up-to-date: setuptools in /usr/local/lib/python3.6/site-packages (40.8.0)
Installing collected packages: pip
  Found existing installation: pip 19.0.2
    Uninstalling pip-19.0.2:
      Successfully uninstalled pip-19.0.2
Successfully installed pip-19.0.3
Collecting numpy
  Downloading https://files.pythonhosted.org/packages/2b/26/07472b0de91851b6656cbc86e2f0d5d3a3128e7580f23295ef58b6862d6c/numpy-1.16.1.zip (5.1MB)
Collecting matplotlib
  Downloading https://files.pythonhosted.org/packages/89/0c/653aec68e9cfb775c4fbae8f71011206e5e7fe4d60fcf01ea1a9d3bc957f/matplotlib-3.0.2.tar.gz (36.5MB)
# HANGS HERE ˆˆˆˆˆ    

Кажется, проблема не в matplotlib, потому что, если я удаляю этот пакет, он зависает в scipy, следующий после numpyи так далее ...

ПРИМЕЧАНИЕ. Я пытаюсь построить производство не на localhost, а скорее на docker-machine.

$ docker-machine ls
NAME              ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER     ERRORS
testdriven-dev    -        virtualbox   Running   tcp://192.168.99.100:2376           v18.09.1   
testdriven-prod   *        amazonec2    Running   tcp://18.234.200.115:2376           v18.09.1 <------ THIS ONE

с:

$ docker-machine env testdriven-dev 
$ eval $(docker-machine env testdriven-prod) 
$ export REACT_APP_WEB_SERVICE_URL=http://18.234.200.115 
$ docker-compose -f docker-compose-prod.yml up -d --build

env было обрезано от любых свисающих изображений.

Почему это происходит?

Редактировать

Следуя советам по комментариям, я SSHed в докер-машинупроверить использование процессора duКольцевая сборка и, в точке зависания , вот что я получаю:

$ docker-machine ssh testdriven-prod free
              total        used        free      shared  buff/cache   available
Mem:        1014540      136296      632136       10712      246108      692056
Swap:             0           0           0

и:

$ docker-machine ssh testdriven-prod df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            488M     0  488M   0% /dev
tmpfs           100M   11M   89M  11% /run
/dev/xvda1       16G  2.2G   14G  14% /
tmpfs           496M     0  496M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           496M     0  496M   0% /sys/fs/cgroup
tmpfs           100M     0  100M   0% /run/user/1000

SSH:

top - 01:34:52 up 18 days, 23:47,  1 user,  load average: 0.00, 0.00, 0.00
Tasks: 109 total,   1 running, 108 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.3 us,  0.0 sy,  0.0 ni, 99.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  1014540 total,   594752 free,   124092 used,   295696 buff/cache
KiB Swap:        0 total,        0 free,        0 used.   698272 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND                                                            
 8363 root      20   0  435240  21768   3124 S  0.3  2.1  30:07.40 containerd  
    1 root      20   0  185312   4916   2996 S  0.0  0.5   0:12.98 systemd  

больше:

ubuntu@testdriven-prod:~$ ps aux -Hww
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         2  0.0  0.0      0     0 ?        S    Feb03   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    Feb03   0:37   [ksoftirqd/0]
root         5  0.0  0.0      0     0 ?        S<   Feb03   0:00   [kworker/0:0H]
root         7  0.0  0.0      0     0 ?        S    Feb03   0:17   [rcu_sched]
root         8  0.0  0.0      0     0 ?        S    Feb03   0:00   [rcu_bh]
root         9  0.0  0.0      0     0 ?        S    Feb03   0:00   [migration/0]
root        10  0.0  0.0      0     0 ?        S    Feb03   0:07   [watchdog/0]
root        11  0.0  0.0      0     0 ?        S    Feb03   0:00   [kdevtmpfs]
root        12  0.0  0.0      0     0 ?        S<   Feb03   0:00   [netns]
root        13  0.0  0.0      0     0 ?        S<   Feb03   0:00   [perf]
root        14  0.0  0.0      0     0 ?        S    Feb03   0:00   [xenwatch]
root        15  0.0  0.0      0     0 ?        S    Feb03   0:00   [xenbus]
root        17  0.0  0.0      0     0 ?        S    Feb03   0:00   [khungtaskd]
root        18  0.0  0.0      0     0 ?        S<   Feb03   0:00   [writeback]
root        19  0.0  0.0      0     0 ?        SN   Feb03   0:00   [ksmd]
root        20  0.0  0.0      0     0 ?        SN   Feb03   0:03   [khugepaged]
root        21  0.0  0.0      0     0 ?        S<   Feb03   0:00   [crypto]
root        22  0.0  0.0      0     0 ?        S<   Feb03   0:00   [kintegrityd]
root        23  0.0  0.0      0     0 ?        S<   Feb03   0:00   [bioset]
root        24  0.0  0.0      0     0 ?        S<   Feb03   0:00   [kblockd]
root        25  0.0  0.0      0     0 ?        S<   Feb03   0:00   [ata_sff]
root        26  0.0  0.0      0     0 ?        S<   Feb03   0:00   [md]
root        27  0.0  0.0      0     0 ?        S<   Feb03   0:00   [devfreq_wq]
root        30  0.0  0.0      0     0 ?        S    Feb03   0:07   [kswapd0]
root        31  0.0  0.0      0     0 ?        S<   Feb03   0:00   [vmstat]
root        32  0.0  0.0      0     0 ?        S    Feb03   0:00   [fsnotify_mark]
root        33  0.0  0.0      0     0 ?        S    Feb03   0:00   [ecryptfs-kthrea]
root        49  0.0  0.0      0     0 ?        S<   Feb03   0:00   [kthrotld]
root        50  0.0  0.0      0     0 ?        S<   Feb03   0:00   [bioset]
root        51  0.0  0.0      0     0 ?        S<   Feb03   0:00   [bioset]
root        52  0.0  0.0      0     0 ?        S<   Feb03   0:00   [bioset]
root        53  0.0  0.0      0     0 ?        S<   Feb03   0:00   [bioset]
root        54  0.0  0.0      0     0 ?        S<   Feb03   0:00   [bioset]
root        55  0.0  0.0      0     0 ?        S<   Feb03   0:00   [bioset]
root        56  0.0  0.0      0     0 ?        S<   Feb03   0:00   [bioset]
root        57  0.0  0.0      0     0 ?        S<   Feb03   0:00   [bioset]
root        58  0.0  0.0      0     0 ?        S<   Feb03   0:00   [bioset]
root        59  0.0  0.0      0     0 ?        S<   Feb03   0:00   [bioset]
root        60  0.0  0.0      0     0 ?        S<   Feb03   0:00   [bioset]
root        61  0.0  0.0      0     0 ?        S<   Feb03   0:00   [bioset]
root        62  0.0  0.0      0     0 ?        S<   Feb03   0:00   [bioset]
root        63  0.0  0.0      0     0 ?        S<   Feb03   0:00   [bioset]
root        64  0.0  0.0      0     0 ?        S<   Feb03   0:00   [bioset]
root        65  0.0  0.0      0     0 ?        S<   Feb03   0:00   [bioset]
root        66  0.0  0.0      0     0 ?        S<   Feb03   0:00   [bioset]
root        67  0.0  0.0      0     0 ?        S<   Feb03   0:00   [bioset]
root        68  0.0  0.0      0     0 ?        S<   Feb03   0:00   [bioset]
root        69  0.0  0.0      0     0 ?        S<   Feb03   0:00   [bioset]
root        70  0.0  0.0      0     0 ?        S<   Feb03   0:00   [bioset]
root        71  0.0  0.0      0     0 ?        S<   Feb03   0:00   [bioset]
root        72  0.0  0.0      0     0 ?        S<   Feb03   0:00   [bioset]
root        73  0.0  0.0      0     0 ?        S<   Feb03   0:00   [bioset]
root        74  0.0  0.0      0     0 ?        S    Feb03   0:00   [scsi_eh_0]
root        75  0.0  0.0      0     0 ?        S<   Feb03   0:00   [scsi_tmf_0]
root        76  0.0  0.0      0     0 ?        S    Feb03   0:00   [scsi_eh_1]
root        77  0.0  0.0      0     0 ?        S<   Feb03   0:00   [scsi_tmf_1]
root        79  0.0  0.0      0     0 ?        S<   Feb03   0:00   [bioset]
root        83  0.0  0.0      0     0 ?        S<   Feb03   0:00   [ipv6_addrconf]
root        96  0.0  0.0      0     0 ?        S<   Feb03   0:00   [deferwq]
root       258  0.0  0.0      0     0 ?        S<   Feb03   0:00   [raid5wq]
root       288  0.0  0.0      0     0 ?        S<   Feb03   0:00   [bioset]
root       310  0.0  0.0      0     0 ?        S    Feb03   0:06   [jbd2/xvda1-8]
root       311  0.0  0.0      0     0 ?        S<   Feb03   0:00   [ext4-rsv-conver]
root       386  0.0  0.0      0     0 ?        S<   Feb03   0:00   [iscsi_eh]
root       389  0.0  0.0      0     0 ?        S<   Feb03   0:00   [ib_addr]
root       392  0.0  0.0      0     0 ?        S<   Feb03   0:00   [ib_mcast]
root       394  0.0  0.0      0     0 ?        S<   Feb03   0:00   [ib_nl_sa_wq]
root       397  0.0  0.0      0     0 ?        S<   Feb03   0:00   [ib_cm]
root       398  0.0  0.0      0     0 ?        S<   Feb03   0:00   [iw_cm_wq]
root       399  0.0  0.0      0     0 ?        S<   Feb03   0:00   [rdma_cm]
root       411  0.0  0.0      0     0 ?        S    Feb03   0:00   [kauditd]
root       541  0.0  0.0      0     0 ?        S<   Feb03   0:02   [kworker/0:1H]
root     23959  0.0  0.0      0     0 ?        S<   Feb03   0:00   [xfsalloc]
root     23960  0.0  0.0      0     0 ?        S<   Feb03   0:00   [xfs_mru_cache]
root     12186  0.0  0.0      0     0 ?        S    Feb21   0:00   [kworker/u30:2]
root     12198  0.0  0.0      0     0 ?        S    00:21   0:00   [kworker/u30:1]
root     12219  0.0  0.0      0     0 ?        S    00:21   0:00   [kworker/0:0]
root     13607  0.0  0.0      0     0 ?        S    02:16   0:00   [kworker/0:2]
root         1  0.0  0.4 185312  5020 ?        Ss   Feb03   0:13 /lib/systemd/systemd --system --deserialize 27
root       366  0.0  0.2  28352  2212 ?        Ss   Feb03   0:04   /lib/systemd/systemd-journald
root       437  0.0  0.0 102968   372 ?        Ss   Feb03   0:00   /sbin/lvmetad -f
root       942  0.0  0.2  16116  2780 ?        Ss   Feb03   0:00   /sbin/dhclient -1 -v -pf /run/dhclient.eth0.pid -lf /var/lib/dhcp/dhclient.eth0.leases -I -df /var/lib/dhcp/dhclient6.eth0.leases eth0
root      1091  0.0  0.2  26068  2048 ?        Ss   Feb03   0:01   /usr/sbin/cron -f
daemon    1097  0.0  0.1  26044  1664 ?        Ss   Feb03   0:00   /usr/sbin/atd -f
message+  1101  0.0  0.1  42992  1704 ?        Ss   Feb03   0:01   /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
root      1110  0.0  0.3 272944  3360 ?        Ssl  Feb03   0:20   /usr/lib/accountsservice/accounts-daemon
root      1113  0.0  0.6 636464  7008 ?        Ssl  Feb03   0:07   /usr/bin/lxcfs /var/lib/lxcfs/
root      1139  0.0  0.2  28616  2452 ?        Ss   Feb03   0:01   /lib/systemd/systemd-logind
syslog    1140  0.0  0.2 260628  2228 ?        Ssl  Feb03   0:01   /usr/sbin/rsyslogd -n
root      1151  0.0  0.1   4396  1312 ?        Ss   Feb03   0:00   /usr/sbin/acpid
root      1157  0.0  0.0   5220   116 ?        Ss   Feb03   0:38   /sbin/iscsid
root      1158  0.0  0.3   5720  3508 ?        S<Ls Feb03   3:04   /sbin/iscsid
root      1172  0.0  0.0  13372   144 ?        Ss   Feb03   0:00   /sbin/mdadm --monitor --pid-file /run/mdadm/monitor.pid --daemonise --scan --syslog
root      1263  0.0  0.1  12840  1588 ttyS0    Ss+  Feb03   0:00   /sbin/agetty --keep-baud 115200 38400 9600 ttyS0 vt220
root      1266  0.0  0.1  14656  1472 tty1     Ss+  Feb03   0:00   /sbin/agetty --noclear tty1 linux
root      8363  0.1  2.1 435240 21768 ?        Ssl  Feb03  30:09   /usr/bin/containerd
root      9248  0.0  5.6 583988 57744 ?        Ssl  Feb03  18:11   /usr/bin/dockerd -H tcp://0.0.0.0:2376 -H unix:///var/run/docker.sock --storage-driver overlay2 --tlsverify --tlscacert /etc/docker/ca.pem --tlscert /etc/docker/server.pem --tlskey /etc/docker/server-key.pem --label provider=amazonec2
root     24091  0.0  0.1 277088  1652 ?        Ssl  Feb03   0:00   /usr/lib/policykit-1/polkitd --no-debug
root      1068  0.0  0.2  65512  2616 ?        Ss   Feb09   0:00   /usr/sbin/sshd -D
root     13498  0.0  0.6  92800  6580 ?        Ss   01:32   0:00     sshd: ubuntu [priv]
ubuntu   13560  0.0  0.3  92800  3352 ?        S    01:32   0:01       sshd: ubuntu@pts/0
ubuntu   13561  0.0  0.5  21388  5104 pts/0    Ss   01:32   0:00         -bash
ubuntu   13617  0.0  0.3  36228  3332 pts/0    R+   02:23   0:00           ps aux -Hww
root     31239  0.0  1.5 292584 15836 ?        Ssl  Feb13   0:20   /usr/lib/snapd/snapd
systemd+ 22714  0.0  0.1 100324  1816 ?        Ssl  Feb20   0:00   /lib/systemd/systemd-timesyncd
root     23340  0.0  0.2  42124  2484 ?        Ss   Feb20   0:00   /lib/systemd/systemd-udevd
ubuntu   13500  0.0  0.4  45148  4608 ?        Ss   01:32   0:00   /lib/systemd/systemd --user
ubuntu   13505  0.0  0.2 208764  2032 ?        S    01:32   0:00     (sd-pam) 
...