Dockerfile, ARG and ENV not working - docker

I have following Dockerfile
#Copyright (c) 2014-2017 Oracle and/or its affiliates. All rights reserved.
#
#Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
#
# ORACLE DOCKERFILES PROJECT
# --------------------------
# This Dockerfile extends the Oracle WebLogic image by creating a sample domain.
#
# Util scripts are copied into the image enabling users to plug NodeManager
# automatically into the AdminServer running on another container.
#
# HOW TO BUILD THIS IMAGE
# -----------------------
# Put all downloaded files in the same directory as this Dockerfile
# Run:
# $ sudo docker build -t 12213-domain
#
# Pull base image
# ---------------
FROM oracle/weblogic:12.2.1.3-developer
# Maintainer
# ----------
MAINTAINER Monica Riccelli <monica.riccelli#oracle.com>
ARG DOMAIN_NAME
ARG ADMIN_PORT
ARG ADMIN_NAME
ARG ADMIN_USERNAME
ARG ADMIN_PASSWORD
# WLS Configuration
# ---------------------------
ENV ADMIN_HOST="wlsadmin" \
NM_PORT="5556" \
MS_PORT="8001" \
DEBUG_PORT="8453" \
ORACLE_HOME=/u01/oracle \
SCRIPT_FILE=/u01/oracle/createAndStartWLSDomain.sh \
CONFIG_JVM_ARGS="-Dweblogic.security.SSL.ignoreHostnameVerification=true" \
PATH=$PATH:/u01/oracle/oracle_common/common/bin:/u01/oracle/wlserver/common/bin:/u01/oracle/user_projects/domains/${DOMAIN_NAME:-base_domain}/bin:/u01/oracle
# Domain and Server environment variables
# ------------------------------------------------------------
ENV DOMAIN_NAME="${DOMAIN_NAME}" \
PRE_DOMAIN_HOME=/u01/oracle/user_projects \
ADMIN_PORT="${ADMIN_PORT}" \
ADMIN_USERNAME="${ADMIN_USERNAME}" \
ADMIN_NAME="${ADMIN_NAME}" \
MS_NAME="${MS_NAME:-""}" \
NM_NAME="${NM_NAME:-""}" \
ADMIN_PASSWORD="${ADMIN_PASSWORD}" \
CLUSTER_NAME="${CLUSTER_NAME:-DockerCluster}" \
DEBUG_FLAG=true \
PRODUCTION_MODE=dev
# Add files required to build this image
COPY container-scripts/* /u01/oracle/
#Create directory where domain will be written to
USER root
RUN chmod +xw /u01/oracle/*.sh && \
chmod +xw /u01/oracle/*.py && \
mkdir -p $PRE_DOMAIN_HOME && \
chmod a+xr $PRE_DOMAIN_HOME && \
chown -R oracle:oracle $PRE_DOMAIN_HOME
VOLUME $PRE_DOMAIN_HOME
# Expose Node Manager default port, and also default for admin and managed server
EXPOSE $NM_PORT $ADMIN_PORT $MS_PORT $DEBUG_PORT
USER oracle
WORKDIR $ORACLE_HOME
# Define default command to start bash.
CMD ["/u01/oracle/createAndStartWLSDomain.sh"]
Which I build using command
#!/bin/sh
#
#Copyright (c) 2014-2017 Oracle and/or its affiliates. All rights reserved.
#
#Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
#
docker build -t 12213-domain \
--no-cache \
--build-arg DOMAIN_NAME=domain \
--build-arg ADMIN_PORT=7001 \
--build-arg ADMIN_NAME=admin \
--build-arg ADMIN_USERNAME=wlsuser \
--build-arg ADMIN_PASSWORD=wlsuser1 \
.
And get the following build log
$ ./build.sh
Sending build context to Docker daemon 51.71kB
Step 1/17 : FROM oracle/weblogic:12.2.1.3-developer
---> 15ba3f59a9f9
Step 2/17 : MAINTAINER Monica Riccelli <monica.riccelli#oracle.com>
---> Running in ac70adb36a4b
Removing intermediate container ac70adb36a4b
---> fe34e24ffce7
Step 3/17 : ARG DOMAIN_NAME
---> Running in 073a89d7613c
Removing intermediate container 073a89d7613c
---> de10930a27d6
Step 4/17 : ARG ADMIN_PORT
---> Running in d213833315c2
Removing intermediate container d213833315c2
---> 9af410c46028
Step 5/17 : ARG ADMIN_NAME
---> Running in 2baee277da54
Removing intermediate container 2baee277da54
---> a76f3f3d6642
Step 6/17 : ARG ADMIN_USERNNAME
---> Running in 9127852dae20
Removing intermediate container 9127852dae20
---> bb9af74b5804
Step 7/17 : ARG ADMIN_PASSWORD
---> Running in 4d0b1969605b
Removing intermediate container 4d0b1969605b
---> af18d5b6be2d
Step 8/17 : ENV ADMIN_HOST="wlsadmin" NM_PORT="5556" MS_PORT="8001"
DEBUG_PORT="8453" ORACLE_HOME=/u01/oracle SCRIPT_FILE=/u01/oracle/create
AndStartWLSDomain.sh CONFIG_JVM_ARGS="-Dweblogic.security.SSL.ignoreHostname
Verification=true" PATH=$PATH:/u01/oracle/oracle_common/common/bin:/u01/ora
cle/wlserver/common/bin:/u01/oracle/user_projects/domains/${DOMAIN_NAME:-base_do
main}/bin:/u01/oracle
---> Running in 449a28590d90
Removing intermediate container 449a28590d90
---> 2a1ddd961d5c
Step 9/17 : ENV DOMAIN_NAME="${DOMAIN_NAME}" PRE_DOMAIN_HOME=/u01/oracle/use
r_projects ADMIN_PORT="${ADMIN_PORT}" ADMIN_USERNAME="${ADMIN_USERNAME}
" ADMIN_NAME="${ADMIN_NAME}" MS_NAME="${MS_NAME:-""}" NM_NAME="${NM_
NAME:-""}" ADMIN_PASSWORD="${ADMIN_PASSWORD}" CLUSTER_NAME="${CLUSTER_NA
ME:-DockerCluster}" DEBUG_FLAG=true PRODUCTION_MODE=dev
---> Running in 0b01881a1ca4
Removing intermediate container 0b01881a1ca4
---> 7a3cd53ea5a3
Step 10/17 : COPY container-scripts/* /u01/oracle/
---> ce67247c3f7e
Step 11/17 : USER root
---> Running in 61adcafc1226
Removing intermediate container 61adcafc1226
---> f9a781fda963
Step 12/17 : RUN chmod +xw /u01/oracle/*.sh && chmod +xw /u01/oracle/*.py &&
mkdir -p $PRE_DOMAIN_HOME && chmod a+xr $PRE_DOMAIN_HOME && chown -
R oracle:oracle $PRE_DOMAIN_HOME
---> Running in 82b7b258d6f1
Removing intermediate container 82b7b258d6f1
---> 0cda254bc640
Step 13/17 : VOLUME $PRE_DOMAIN_HOME
---> Running in 6650ff8092d3
Removing intermediate container 6650ff8092d3
---> c469ff0ac9a2
Step 14/17 : EXPOSE $NM_PORT $ADMIN_PORT $MS_PORT $DEBUG_PORT
---> Running in a551b6bd5363
Removing intermediate container a551b6bd5363
---> 08253c4d94bd
Step 15/17 : USER oracle
---> Running in f1e6b4e482e9
Removing intermediate container f1e6b4e482e9
---> 85a75641e866
Step 16/17 : WORKDIR $ORACLE_HOME
Removing intermediate container a2b75ecbb0b6
---> 0124a8251ce3
Step 17/17 : CMD ["/u01/oracle/createAndStartWLSDomain.sh"]
---> Running in 1455fdc0d39d
Removing intermediate container 1455fdc0d39d
---> c1c947c2816c
[Warning] One or more build-args [ADMIN_USERNAME] were not consumed
Successfully built c1c947c2816c
Successfully tagged 12213-domain:latest
SECURITY WARNING: You are building a Docker image from Windows against a non-Win
dows Docker host. All files and directories added to build context will have '-r
wxr-xr-x' permissions. It is recommended to double check and reset permissions f
or sensitive files and directories.
Note the message
[Warning] One or more build-args [ADMIN_USERNAME] were not consumed
When I start the container and print the environment
FMW_PKG=fmw_12.2.1.3.0_wls_quick_Disk1_1of1.zip
CONFIG_JVM_ARGS=-Dweblogic.security.SSL.ignoreHostnameVerification=true
HOSTNAME=74adf82e8092
PRODUCTION_MODE=dev
TERM=xterm
ADMIN_NAME=AdminServer
CLUSTER_NAME=DockerCluster
FMW_JAR=fmw_12.2.1.3.0_wls_quick.jar
USER_MEM_ARGS=-Djava.security.egd=file:/dev/./urandom
DEBUG_FLAG=true
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd
=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;4
2:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:
*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=0
1;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;
31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=0
1;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sa
r=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:
*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01
;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.ti
ff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;3
5:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp
4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:
*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01
;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=
01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.f
lac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;
36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:
MS_NAME=
DOMAIN_NAME=base_domain
SCRIPT_FILE=/u01/oracle/createAndStartWLSDomain.sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/java/defa
ult/bin:/u01/oracle/oracle_common/common/bin:/u01/oracle/wlserver/common/bin:/u0
1/oracle/oracle_common/common/bin:/u01/oracle/wlserver/common/bin:/u01/oracle/us
er_projects/domains/base_domain/bin:/u01/oracle
ADMIN_HOST=wlsadmin
DOMAIN_HOME=/u01/oracle/user_projects/domains/base_domain
NM_NAME=
PWD=/u01/oracle
DEBUG_PORT=8453
ADMIN_PORT=7001
JAVA_HOME=/usr/java/default
JAVA_PKG=server-jre-8u*-linux-x64.tar.gz
SHLVL=1
HOME=/u01/oracle
ADMIN_USERNAME=weblogic
NM_PORT=5556
PRE_DOMAIN_HOME=/u01/oracle/user_projects
ADMIN_PASSWORD=
ORACLE_HOME=/u01/oracle
MS_PORT=8001
_=/usr/bin/env
The environment variables are not set correctly, but uses the environment variables from the base image. I want to override those variables.
EDIT:
The problem is either --build-arg not passing the parameters to ARG, or ARG not correctly binding to ENV. Environment is overridden correctly, if I use constant string in the ENV. Even more interestingly, if I don't pass --build-arg to those ARG variables, I don't get any warning or error and still get the exactly same build log. AFAIK, unbound ARG without default value should raise an error.
Is this a bug? I'm using docker-toolbox on windows, and here is the docker version
docker-machine.exe version 0.14.0, build 89b8332
Docker version 18.03.0-ce, build 0520e24302

From docs.docker.com:
Environment variables defined using the ENV instruction always
override an ARG instruction of the same name
So the only way to resolve this is to use different name for ARG variables.
There is a typo in your ARG declaration.
I think change that to ADMIN_USERNAME will fix your problem.

Related

How to create directory in docker image?

I tried mkdir -p it didn't work.
I have the following Dockerfile:
FROM jenkins/jenkins:2.363-jdk11
ENV PLUGIN_DIR /var/jenkins_home/plugins
RUN echo $PLUGIN_DIR
RUN mkdir -p $PLUGIN_DIR
RUN ls $PLUGIN_DIR
# WORKDIR /var/jenkins_home/plugins # Can't use this, as it changes the permission to root
# which breaks the plugin installation step
# # COPY plugins.txt /usr/share/jenkins/plugins.txt
# # RUN jenkins-plugin-cli -f /usr/share/jenkins/plugins.txt --verbose
#
#
# # disable the setup wizard as we will set up jenkins as code
# ENV JAVA_OPTS -Djenkins.install.runSetupWizard=false
#
# ENV CASC_JENKINS_CONFIG /configs/jcasc.yaml
The build fails!
docker build -t jenkins:test.1 .
Sending build context to Docker daemon 51.2kB
Step 1/5 : FROM jenkins/jenkins:2.363-jdk11
---> 90ff7cc5bfd1
Step 2/5 : ENV PLUGIN_DIR /var/jenkins_home/plugins
---> Using cache
---> 0a158958aab0
Step 3/5 : RUN echo $PLUGIN_DIR
---> Running in ce56ef9146fc
/var/jenkins_home/plugins
Step 4/5 : RUN mkdir -p $PLUGIN_DIR
---> Using cache
---> dbc4e12b9808
Step 5/5 : RUN ls $PLUGIN_DIR
---> Running in 9a0edb027862
I need this because Jenkins deprecated old plugin installation method. The new cli installs plugins to /usr/share/jenkins/ref/plugins instead.
Also:
+$ docker run -it --rm --entrypoint /bin/bash --name jenkins jenkins:test.1
jenkins#7ad71925f638:/$ ls /var/jenkins_home/
jenkins#7ad71925f638:/$
The official Jenkins image on dockerhub declare VOLUME /var/jenkins_home, and subsequent changes to that directory (even in derived images) are discarded.
To workaround, you can execute mkdir as ENTRYPOINT.
And to verify that its working you can add an sleep to enter into the container and verify. It work !.
FROM jenkins/jenkins:2.363-jdk11
ENV PLUGIN_DIR /var/jenkins_home/plugins
RUN echo $PLUGIN_DIR
USER root
RUN echo "#!/bin/sh \n mkdir -pv $PLUGIN_DIR && sleep inf" > ./mkdir.sh
RUN chmod a+x ./mkdir.sh
USER jenkins
ENTRYPOINT [ "/bin/sh", "-c", "./mkdir.sh"]
after
docker build . -t <image_name>
docker run -d <image_name> --name <container_name>
docker exec -it <container_name> bash
and you will see your directory
Sources:
https://forums.docker.com/t/simple-mkdir-p-not-working/42179
https://hub.docker.com/_/jenkins

Docker build creates and tags an image that docker run cannot find

I have been given a project that is in a Docker container. I have managed to build the Docker container image and tag it, but when I run it I have problems.
bash-5.1$ docker build -t game:0.0.1 -t game:latest .
Sending build context to Docker daemon 2.584MB
Step 1/12 : FROM nvidia/cuda:10.2-base-ubuntu18.04
---> 84b82c2f5736
Step 2/12 : MAINTAINER me
---> Using cache
---> b8a86a8860d5
Step 3/12 : EXPOSE 5006
---> Using cache
---> fabdfc06768c
Step 4/12 : EXPOSE 8888
---> Using cache
---> a6f8585ce52d
Step 5/12 : ENV DEBIAN_FRONTEND noninteractive
---> Using cache
---> c4dd4de87fdc
Step 6/12 : ENV WD=/home/game/
---> Using cache
---> 871163f5db29
Step 7/12 : WORKDIR ${WD}
---> Using cache
---> 36678a12e551
Step 8/12 : RUN apt-get -y update && apt-get -y upgrade && apt-get -y install git ssh pkg-config python3-pip python3-opencv
---> Using cache
---> 4b83b4944484
Step 9/12 : COPY requirements.txt /requirements.txt
---> Using cache
---> 8e1db9206e80
Step 10/12 : RUN cd / && python3 -m pip install --upgrade pip && pip3 install -r requirements.txt
---> Using cache
---> e096029d458a
Step 11/12 : CMD ["start.py"]
---> Using cache
---> 795bb5a65bc8
Step 12/12 : ENTRYPOINT ["python3"]
---> Using cache
---> 59b472b693f2
Successfully built 59b472b693f2
Successfully tagged game:0.0.1
Successfully tagged game:latest
bash-5.1$ docker run -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix game:latest
Unable to find image 'game:latest' locally
docker: Error response from daemon: pull access denied for game, repository does not exist or may require 'docker login': denied: requested access to the resource is denied.
See 'docker run --help'.
bash-5.1$ sudo docker run -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix game:latest
It doesn't seem to find the game:latest image even though the output of the above command says it just created it.
I also try to do this after logging into my session.
I tried to run 59b472b693f2 (what is it, is it a container hash code?):
bash-5.1$ docker run 59b472b693f2
python3: can't open file 'start.py': [Errno 2] No such file or directory
bash-5.1$ ls
data_collection demonstrateur.ipynb demo.py Dockerfile examples README.md requirements.txt serious_game start.py test
bash-5.1$
Here is the list of available images:
bash-5.1$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
game 0.0.1 7e7ad7272cf0 15 minutes ago 1.77GB
game latest 7e7ad7272cf0 15 minutes ago 1.77GB
ubuntu latest ba6acccedd29 7 weeks ago 72.8MB
hello-world latest feb5d9fea6a5 2 months ago 13.3kB
nvidia/cuda 10.2-base-ubuntu18.04 84b82c2f5736 2 months ago 107MB
bash-5.1$ docker run -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix game:latest
python3: can't open file 'start.py': [Errno 2] No such file or directory
bash-5.1$
I tried to add it in the Dockerfile but still got the same error:
Removing intermediate container 10f2d7506d17
---> 1b776923e5a9
Step 11/13 : COPY start.py /start.py
---> 172c81ff16e9
Step 12/13 : CMD ["start.py"]
---> Running in c7217e2e0f21
Removing intermediate container c7217e2e0f21
---> eaf947ffa0b1
Step 13/13 : ENTRYPOINT ["python3"]
---> Running in 77e2e7b90658
Removing intermediate container 77e2e7b90658
---> 924d8c473e36
Successfully built 924d8c473e36
Successfully tagged seriousgame:0.0.1
Successfully tagged seriousgame:latest
bash-5.1$ docker run -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix seriousgame:latest
python3: can't open file 'start.py': [Errno 2] No such file or directory
Here is my Dockerfile:
#############################################################################################################
#
# Creation du container
#
##############################################################################################################
FROM nvidia/cuda:10.2-base-ubuntu18.04
MAINTAINER me
EXPOSE 5006
EXPOSE 8888
ENV DEBIAN_FRONTEND noninteractive
ENV WD=/home/game/
WORKDIR ${WD}
# Add git and ssh
RUN apt-get -y update && \
apt-get -y upgrade && \
apt-get -y install git ssh pkg-config python3-pip python3-opencv
# Dépendances python
COPY requirements.txt /requirements.txt
RUN cd / && \
python3 -m pip install --upgrade pip && \
pip3 install -r requirements.txt
COPY start.py /start.py
CMD ["start.py"]
ENTRYPOINT ["python3"]
Here are all the files within my project:
bash-5.1$ ls
data_collection demonstrateur.ipynb demo.py Dockerfile examples README.md requirements.txt serious_game start.py test
In the first block of code you posted it says Successfully tagged game:latest and Successfully tagged game:0.0.1, but in your docker images output you don't see those images. Looking at the output of your docker images I see that the last time you built the image named serious-game was 1 hour ago. I'm guessing so that you tried to rename the image, but the image ID didn't change.
You can try to remove the old image with docker image rm command (docs), and then try to build it again. The commands sequence to execute is the code block below. Data should be safe becouse I see that you're using volumes (I assume that you know what you're doing).
docker image rm 59b472b693f2
docker build -t game:0.0.1 -t game:latest .
The sequence 59b472b693f2 is the unique ID of the image in your Docker local environment (you can assume that it's an ID like the ones used in databases for indexing).

Docker container not showing site based on newly copied site configuration

This is my Dockerfile.
FROM ubuntu:devel
MAINTAINER ciasto
RUN apt-get update && apt-get install -y apache2 && apt-get clean && rm -rf /var/lib/apt/lists/\*
RUN mkdir /var/run/apache2
COPY mysite.conf /etc/apache2/sites-available/000-default.conf
ENV APACHE\_RUN\_USER www-data
ENV APACHE\_RUN\_GROUP www-data
ENV APACHE\_LOG\_DIR /var/log/apache2
ENV APACHE\_RUN\_DIR /var/run/apache2
EXPOSE 80
CMD \["/usr/sbin/apache2", "-D", "FOREGROUND"\]
I am trying to load my site instead of default 000-default.conf but even though the mysite.conf overwrites 000-default.conf I still keep getting the default homepage of Apache instead.
It doesn't have any affect of a2dissite and then running a2ensite:
# docker build -t myapache .
Sending build context to Docker daemon 3.072kB
Step 1/13 : FROM ubuntu:devel
---> 3dd27c0da934
Step 2/13 : MAINTAINER ciasto
---> Using cache
---> ca48c7010bf5
Step 3/13 : RUN apt-get update && apt-get install -y apache2 && apt-get clean && rm -rf /var/lib/apt/lists/*
---> Using cache
---> 3893438f7d96
Step 4/13 : RUN mkdir /var/run/apache2
---> Using cache
---> 6cc65fe8d352
Step 5/13 : COPY mysite.conf /etc/apache2/sites-available/000-default.conf
---> Using cache
---> 469c402f7c57
Step 6/13 : RUN a2dissite 000-default
---> Running in 2de611818fc0
Site 000-default disabled.
To activate the new configuration, you need to run:
service apache2 reload
Removing intermediate container 2de611818fc0
---> 64d8deed8833
Step 7/13 : RUN a2ensite 000-default
---> Running in cc8a0374ab0d
Enabling site 000-default.
To activate the new configuration, you need to run:
service apache2 reload
Removing intermediate container cc8a0374ab0d
---> 3af0de88b74b
Step 8/13 : ENV APACHE_RUN_USER www-data
---> Running in fa2146657f5f
Removing intermediate container fa2146657f5f
---> dac302f42282
Step 9/13 : ENV APACHE_RUN_GROUP www-data
---> Running in 7a3035b5866d
Removing intermediate container 7a3035b5866d
---> fdfc7a1d86e4
Step 10/13 : ENV APACHE_LOG_DIR /var/log/apache2
---> Running in 93cc22c81f55
Removing intermediate container 93cc22c81f55
---> d8e073243eed
Step 11/13 : ENV APACHE_RUN_DIR /var/run/apache2
---> Running in ca2b2829d60c
Removing intermediate container ca2b2829d60c
---> c7f535e2c031
Step 12/13 : EXPOSE 80
---> Running in 613564334e15
Removing intermediate container 613564334e15
---> adae0f0e2aed
Step 13/13 : CMD ["apachectl", "-D", "FOREGROUND"]
---> Running in 97c845feed9f
Removing intermediate container 97c845feed9f
---> 67f7823b995b
Successfully built 67f7823b995b
Successfully tagged myapache:latest
then I still get default page of Apache and checked by entering running container:
# apachectl -S
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/run/apache2/" mechanism=default
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33
This should fix your problem here. To be add after the COPY:
RUN a2dissite 000-default
RUN a2ensite 000-default

Docker build failed to copy a file

Hi I am new to Docker and trying to wrap around my head on how to clone a private repo from github and found some interesting link issues/6396
I followed one of the post and my dockerfile looks like
FROM python:2.7 as builder
# Deploy app's code
#RUN set -x
RUN mkdir /code
RUN mkdir /root/.ssh/
RUN ls -l /root/.ssh/
# The GITHUB_SSH_KEY Build Argument must be a path or URL
# If it's a path, it MUST be in the docker build dir, and NOT in .dockerignore!
ARG SSH_PRIVATE_KEY=C:\\Users\\MyUser\\.ssh\\id_rsa
RUN echo "${SSH_PRIVATE_KEY}"
# Set up root user SSH access for GitHub
ADD ${SSH_PRIVATE_KEY} /root/.ssh/id_rsa
RUN ssh -o StrictHostKeyChecking=no -vT git#github.com 2>&1 | grep -i auth
# Test SSH access (this returns false even when successful, but prints results)
RUN git clone git#github.com:***********.git
COPY . /code
WORKDIR /code
ENV PYTHONPATH /datawarehouse_process
# Setup app's virtualenv
RUN set -x \
&& pip install tox \
&& tox -e luigi
WORKDIR /datawarehouse_process
# Finally, remove the $GITHUB_SSH_KEY if it was a file, so it's not in /app!
# It can also be removed from /root/.ssh/id_rsa, but you're probably not
going
# to COPY that directory into the runtime image.
RUN rm -vf ${GITHUB_SSH_KEY} /root/.ssh/id*
#FROM python:2.7 as runtime
#COPY --from=builder /code /code
When I run docker build . from the correct location I get this error below. Any clue will be appreciated.
c:\Domain\Project\Docker-Images\datawarehouse_process>docker build .
Sending build context to Docker daemon 281.7MB
Step 1/15 : FROM python:2.7 as builder
---> 43c5f3ee0928
Step 2/15 : RUN mkdir /code
---> Running in 841fadc29641
Removing intermediate container 841fadc29641
---> 69fdbcd34f12
Step 3/15 : RUN mkdir /root/.ssh/
---> Running in 50199b0eb002
Removing intermediate container 50199b0eb002
---> 6dac8b120438
Step 4/15 : RUN ls -l /root/.ssh/
---> Running in e15040402b79
total 0
Removing intermediate container e15040402b79
---> 65519edac99a
Step 5/15 : ARG SSH_PRIVATE_KEY=C:\\Users\\MyUser\\.ssh\\id_rsa
---> Running in 10e0c92eed4f
Removing intermediate container 10e0c92eed4f
---> 707279c92614
Step 6/15 : RUN echo "${SSH_PRIVATE_KEY}"
---> Running in a9f75c224994
C:\Users\MyUser\.ssh\id_rsa
Removing intermediate container a9f75c224994
---> 96e0605d38a9
Step 7/15 : ADD ${SSH_PRIVATE_KEY} /root/.ssh/id_rsa
ADD failed: stat /var/lib/docker/tmp/docker-
builder142890167/C:\Users\MyUser\.ssh\id_rsa: no such file or
directory
From the Documentation:
ADD obeys the following rules:
The path must be inside the context of the build; you cannot ADD
../something /something, because the first step of a docker build is
to send the context directory (and subdirectories) to the docker
daemon.
You are passing an absolute path to ADD, but you can see from the error:
/var/lib/docker/tmp/docker-builder142890167/C:\Users\MyUser\.ssh\id_rsa:
no such file or directory
It is being looked for within the build context. Again from the documentation:
Traditionally, the Dockerfile is called Dockerfile and located in the
root of the context.
So, you need to place the RSA key somewhere in the directory tree which has it's root at the path that you specify in your Docker build command, so if you are entering docker build . your ARG statement would change to something like:
ARG SSH_PRIVATE_KEY = .\.ssh\id_rsa

How to pass ARG value to ENTRYPOINT?

Docker 1.9 allows to pass arguments to a dockerfile. See link: https://docs.docker.com/engine/reference/builder/#arg
How can i pass the same arugments within ENTRYPOINT Instruction??
My dockerfile has
ARG $Version=3.1
ENTRYPOINT /tmp/folder-$Version/sample.sh start
I am getting an error while creating container with above dockerfile.
Please suggest what is the correct way to specify the argument within ENTRYPOINT instruction??
Like Blake Mitchell sais, you cannot use ARG in ENTRYPOINT. However you can use your ARG as a value for ENV, that way you can use it with ENTRYPOINT:
Dockerfile
ARG my_arg
ENV my_env_var=$my_arg
ENTRYPOINT echo $my_env_var
and run:
docker build --build-arg "my_arg=foo" ...
Short answer: you need to use ENV
Both ARG and ENV are not expanded in ENTRYPOINT or CMD. (https://docs.docker.com/engine/reference/builder/#environment-replacement) However, because ENVs are passed in as part of the environment, they are available at run time, so the shell can expand them. (This means you can't use the array form of ENTRYPOINT or CMD.)
Here is an example:
$ cat arg/Dockerfile
FROM debian:jessie
ARG FOO=bar
ENTRYPOINT echo ${FOO:-foo}
$ sudo docker build arg
Sending build context to Docker daemon 2.048 kB
Step 1 : FROM debian:jessie
---> f50f9524513f
Step 2 : ARG FOO=bar
---> Using cache
---> 2cfdcb514b62
Step 3 : ENTRYPOINT echo ${FOO:-foo}
---> Running in 21fb9b42c10d
---> 75e5018bad83
Removing intermediate container 21fb9b42c10d
Successfully built 75e5018bad83
$ sudo docker run 75e5018bad83
foo
$ sudo docker run -e FOO=bas 75e5018bad83
bas
$ sudo docker build --build-arg FOO=bas arg
Sending build context to Docker daemon 2.048 kB
Step 1 : FROM debian:jessie
---> f50f9524513f
Step 2 : ARG FOO=bar
---> Using cache
---> 2cfdcb514b62
Step 3 : ENTRYPOINT echo ${FOO:-foo}
---> Using cache
---> 75e5018bad83
Successfully built 75e5018bad83
$ sudo docker run 75e5018bad83
foo
$ cat env/Dockerfile
FROM debian:jessie
ARG FOO=bar
ENV FOO=${FOO}
ENTRYPOINT echo ${FOO:-foo}
$ sudo docker build env
Sending build context to Docker daemon 2.048 kB
Step 1 : FROM debian:jessie
---> f50f9524513f
Step 2 : ARG FOO=bar
---> Using cache
---> 2cfdcb514b62
Step 3 : ENV FOO ${FOO}
---> Running in f157a07c1b3e
---> a5e8c5b65a17
Removing intermediate container f157a07c1b3e
Step 4 : ENTRYPOINT echo ${FOO:-foo}
---> Running in 66e9800ef403
---> 249fe326e9ce
Removing intermediate container 66e9800ef403
Successfully built 249fe326e9ce
$ sudo docker run 249fe326e9ce
bar
$ sudo docker run -e FOO=bas 249fe326e9ce
bas
$ sudo docker build --build-arg FOO=bas env
Sending build context to Docker daemon 2.048 kB
Step 1 : FROM debian:jessie
---> f50f9524513f
Step 2 : ARG FOO=bar
---> Using cache
---> 2cfdcb514b62
Step 3 : ENV FOO ${FOO}
---> Running in 6baf31684b9f
---> 8f77ad154798
Removing intermediate container 6baf31684b9f
Step 4 : ENTRYPOINT echo ${FOO:-foo}
---> Running in 892ac47cabed
---> fa97da85bf8a
Removing intermediate container 892ac47cabed
Successfully built fa97da85bf8a
$ sudo docker run fa97da85bf8a
bas
$
Just in case you have more than one parameter to pass to ENTRYPOINT or CMD, you can do like that:
FROM openjdk:8-jdk-alpine
ARG PROFILE
ENV PROFILE=${PROFILE}
...
CMD java -jar -Dspring.profiles.active=$(echo ${PROFILE}) /app/server.jar
I'm struggling with this for a day, thanks for #Rotareti for mentioning. It needs to be in ENV before it can be used to the ENTRYPOINT.
ENV variable=$from_ARG_variable
ENTRYPOINT exec your_exec_sh_file $variable
Hope this helps.
The syntax for ARG should omit the $.
Instead of ARG $Version=3.1, try ARG Version=3.1.

Resources