Questions tagged [dockerfile]

1.7k

votes
10

answer
489.3k

Views

What is the difference between the `COPY` and `ADD` commands in a Dockerfile?

What is the difference between the COPY and ADD commands in a Dockerfile, and when would I use one over the other? COPY The COPY instruction will copy new files from and add them to the container's filesystem at path ADD The ADD instruction will copy new files from and add them to the contain...
Steve
141

votes
3

answer
121.9k

Views

How to set image name in Dockerfile?

You can set image name when building a custom image, like this: docker build -t dude/man:v2 . # Will be named dude/man:v2 Is there a way to define the name of the image in Dockerfile, so I don't have to mention it in the docker build command?
gvlasov
154

votes
25

answer
101.6k

Views

denied: requested access to the resource is denied : docker

I am following this link to create my first docker Image and it went successfully and now I am trying to push this Image into my docker repository from this link. But whenever I am trying to push this Image into repository , I got this type of error. denied: requested access to the resource is den...
Keyur Shah
73

votes
16

answer
98.1k

Views

Docker: unable to prepare context: unable to evaluate symlinks in Dockerfile path: GetFileAttributesEx

I just downloaded Docker Toolbox for Windows 10 64bit today. I'm going through the tutorial. I'm receving the following error when trying to build an image using a Dockerfile. Steps: Launched Docker Quickstart terminal. testdocker after creating it. Prepare Dockerfile as documented in 'Build your...
villanux
40

votes
3

answer
97.6k

Views

Run a script in Dockerfile

I'm trying to run a script during my building process in my Dockerfile. But it doesn't seems to work. I tried that way: FROM php:7-fpm ADD bootstrap.sh / ENTRYPOINT ['/bin/bash', '/bootstrap.sh'] Also this way: FROM php:7-fpm ADD bootstrap.sh / RUN bash -c '/bootstrap.sh' And also bu executing m...
Kevin
68

votes
7

answer
92.5k

Views

How to correctly link php-fpm and Nginx Docker containers?

I am trying to link 2 separate containers: nginx:latest php:fpm The problem is that php scripts do not work. Perhaps the php-fpm configuration is incorrect. Here is the source code, which is in my repository. Here is the file docker-compose.yml: nginx: build: . ports: - '80:80' - '443:443' volumes:...
Victor Bocharsky
140

votes
2

answer
91.9k

Views

Dockerfile copy keep subdirectory structure

I'm trying to copy a number of files and folders to a docker image build from my localhost. The files are like this: folder1 file1 file2 folder2 file1 file2 I'm trying to make the copy like this: COPY files/* /files/ However, all files are placed in /files/ is there a way in Docker to keep the subdi...
user1220022
169

votes
2

answer
91.3k

Views

Difference between links and depends_on in docker_compose.yml

According to the Docker Compose's compose-file documentation: depends_on - Express dependency between services. links - Link to containers in another service and also express dependency between services in the same way as depends_on. I don't understand the purpose of linking to other containers so t...
itsjef
63

votes
9

answer
82.2k

Views

Docker is installed but Docker Compose is not ? why?

I have installed docker on centos 7. by running following commands, curl -sSL https://get.docker.com/ | sh systemctl enable docker && systemctl start docker docker run hello-world NOTE: helloworld runs correctly and no issues. however when i trying to run docker-compose (docker-compose.yml exists a...
mahen3d
203

votes
6

answer
78.6k

Views

Docker Compose vs. Dockerfile - which is better?

I have been reading up and learning about Docker, and am trying to correctly choose the Django setup to use. So far there is either: Docker Compose or Dockerfile I understand that Dockerfiles are used in Docker Compose, but I am not sure if it is good practice to put everything in one large Dockerfi...
Aaron Lelevier
51

votes
3

answer
68k

Views

How to pass arguments within docker-compose?

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 arguments within docker-compose.yml? Please provide an example too, if possible.
meallhour
130

votes
3

answer
67.9k

Views

How to copy multiple files in one layer using a Dockerfile?

The following Dockerfile contains four COPY layers: COPY README.md ./ COPY package.json ./ COPY gulpfile.js ./ COPY __BUILD_NUMBER ./ How to copy these files using one layer instead? The following was tried: COPY [ '__BUILD_NUMBER ./', 'README.md ./', 'gulpfile ./', 'another_file ./', ]
kazhuravlev
69

votes
4

answer
65k

Views

How to define a variable in a Dockerfile?

In my Dockerfile, I would like to define variables that I can use later in the Dockerfile. I am aware of the ENV instruction, but I do no want these variables to be environment variables. Is there a way to declare variables at Dockerfile scope?
Maxime
65

votes
1

answer
64.1k

Views

Docker expose all ports or range of ports from 7000 to 8000

Can I specify a port range in a Dockerfile EXPOSE 7000-8000 and when running the container bind all these exposed ports to the same ports on the host machine? docker run -p 7000-8000:7000-8000
DarVar
71

votes
1

answer
63.9k

Views

How to pass arguments to a Dockerfile?

I am using RUN instruction within a Dockerfile to install a rpm RUN yum -y install samplerpm-2.3 However, I want to pass the value '2.3' as an argument. My RUN instruction should look something like: RUN yum -y install samplerpm-$arg where $arg=2.3
meallhour
15

votes
2

answer
62.7k

Views

How to use docker container as apache server?

I just started using docker and followed following tutorial: https://docs.docker.com/engine/admin/using_supervisord/ FROM ubuntu:14.04 RUN apt-get update && apt-get upgrade RUN apt-get install -y openssh-server apache2 supervisor RUN mkdir -p /var/lock/apache2 /var/run/apache2 /var/run/sshd /var/log...
Artjom Zabelin
75

votes
10

answer
57.6k

Views

How to mount local volumes in docker machine

I am trying to use docker-machine with docker-compose. The file docker-compose.yml has definitions as follows: web: build: . command: ./run_web.sh volumes: - .:/app ports: - '8000:8000' links: - db:db - rabbitmq:rabbit - redis:redis When running docker-compose up -d all goes well until trying to exe...
jdcaballerov
182

votes
4

answer
55.5k

Views

How do I make a comment in a Dockerfile?

I am writing a Dockerfile and I want to know if there is any way to make comments in this file? Does docker have a comment option that takes the rest of a line and ignores it?
kpie
43

votes
6

answer
53.9k

Views

How to update /etc/hosts file in Docker image during “docker build”

I want to update my /etc/hosts file during 'docker build'. I added below line in Dockerfile but it's neither updating /etc/hosts file nor giving any error. RUN echo '192.168.33.11 mynginx' >> /etc/hosts I need to update /etc/hosts. Can anyone suggest on this?
Prakash
35

votes
4

answer
53.7k

Views

How to copy file from host to container using Dockerfile

I have written a Dockerfile which looks like this FROM ubuntu:12.04 RUN apt-get update RUN apt-get install -y wget Now I'm having a file called abc.txt in my host machine. How can I copy it to this container. Is there any step that I can add in Dockerfile which copy from Host to Container.
59

votes
1

answer
49.3k

Views

ARG or ENV, which one to use in this case?

This could be maybe a trivial question but reading docs for ARG and ENV doesn't put things clear to me. I am building a PHP-FPM container and I want to give the ability for enable/disable some extensions on user needs. Would be great if this could be done in the Dockerfile by adding conditionals an...
ReynierPM
138

votes
6

answer
44.6k

Views

Difference between RUN and CMD in a docker file

I'm confused about when should I use CMD vs RUN. For example, to execute bash/shell commands (i.e. ls -la) I would always use CMD or is there a situation where I would use RUN? Trying to understand the best practices about these two similar Dockerfile directives.
TakeSoUp
137

votes
6

answer
44.3k

Views

What's the difference between RUN and CMD in a docker file and when should I use one or the other?

I'm confused about when should I use CMD vs RUN. For example, to execute bash/shell commands (i.e. ls -la) I would always use CMD or is there a situation where I would use RUN? Trying to understand the best practices about these two similar Dockerfile directives.
TakeSoUp
48

votes
1

answer
43.4k

Views

Multiple FROMs - what it means

I want to build a docker image for the Linkurious project on github, which requires both the Neo4j database, and Node.js to run. my first approach was to declare a base image for my image, containing Neo4j. The reference docs do not define 'base image' in any helpful manner: Base image: An image th...
ekkis
29

votes
1

answer
41.9k

Views

Run jar file in docker image

I create a docker image with java and coppying jar file in image . My Dockerfile is : FROM anapsix/alpine-java MAINTAINER myNAME COPY testprj-1.0-SNAPSHOT.jar /home/testprj-1.0-SNAPSHOT.jar RUN java -jar /home/testprj-1.0-SNAPSHOT.j After execute following command docker build -t imageName. In co...
Svetoslav Angelov
44

votes
4

answer
40.9k

Views

What's the default WORKDIR in docker?

We can use WORKDIR to set a directory as work directory in Dockerfile, but what's the default value if we don't set?
Freewind
41

votes
5

answer
40.8k

Views

Dockerfile if else condition with external arguments

I have dockerfile FROM centos:7 ENV foo=42 then I build it docker build -t my_docker . and run it. docker run -it -d my_docker Is it possible to pass arguments from command line and use it with if else in Dockerfile? I mean something like FROM centos:7 if (my_arg==42) {ENV=TRUE} else: {ENV=FALSE}...
nick_gabpe
25

votes
3

answer
40.7k

Views

The command '/bin/sh -c returned a non-zero code: 127

I'm new to docker so I might be doing this wrong, but I'm trying to install Tomcat6 through a Dockerfile which like this: FROM rhel7:latest RUN cd /tmp RUN 'wget', 'http://www.us.apache.org/dist/tomcat/tomcat-6/v6.0.44/bin/apache-tomcat-6.0.44.tar.gz' RUN tar xzf apache-tomcat-6.0.44.tar.gz RUN mv a...
user5201726
31

votes
1

answer
38.9k

Views

Rebuild Docker container on file changes

For running an ASP.NET Core application, I generated a dockerfile which build the application and copys the source code in the container, which is fetched by Git using Jenkins. So in my workspace, I do the following in the dockerfile: WORKDIR /app COPY src src While Jenkins updates the files on my...
Lion
20

votes
6

answer
38.5k

Views

Docker build gives “unable to prepare context: context must be a directory: /Users/tempUser/git/docker/Dockerfile”

I have a Dockerfile that is supposed to build an Ubuntu image. But when ever I run docker build -t ubuntu-test:latest ./Dockerfile It shows the following error on the console unable to prepare context: context must be a directory: /Users/tempUser/git/docker/Dockerfile I'm on Mac OsX. I tried to sud...
Damien-Amen
22

votes
4

answer
36.2k

Views

Correct way to deploy WAR files in docker image

What is the docker way to deploy java projects in a docker container? Do I copy the war into webapps: FROM jetty:9.2.10 MAINTAINER Me '[email protected]' ADD ./target/*.war /var/lib/jetty/webapps/ROOT.war or do I take the exploded war file: FROM jetty:9.2.10 MAINTAINER Me '[email protected]' ADD ./target/app-0.1.0....
47

votes
5

answer
36.2k

Views

How to cache the RUN npm install instruction when docker build a Dockerfile

I am currently developing a Node backend for my application. When dockerizing it (docker build .) the longest phase is the RUN npm install. The RUN npm install instruction runes on every small server code change, impacting the productivity by making the developer wait for the build to finish each t...
ohadgk
57

votes
7

answer
35.9k

Views

How to name Dockerfiles

I'm unsure of how to name Dockerfiles. Many on GitHub use Dockerfile without a file extension. Do I give them a name and extension; if so what? Or do I just call them Dockerfile?
Lloyd R. Prentice
15

votes
7

answer
35.6k

Views

How to copy folders to docker image from Dockerfile?

I tried the following command in my Dockerfile: COPY * / and got mighty surprised at the result. Seems the naive docker code traverses the directories from the glob and then dumps the each file in the target directory while respectfully ignoring my directory structure. At least that is how I unders...
jonalv
108

votes
4

answer
34.3k

Views

Add a volume to Docker, but exclude a sub-folder

Supposed I have a Docker container and a folder on my host /hostFolder. Now if I want to add this folder to the Docker container as a volume, then I can do this either by using ADD in the Dockerfile or mounting it as a volume. So far, so good. Now /hostFolder contains a sub-folder, /hostFolder/subFo...
Golo Roden
34

votes
3

answer
34.2k

Views

Docker Copy and change owner

Given the following Dockerfile FROM ubuntu RUN groupadd mygroup RUN useradd -ms /bin/bash -G mygroup john MKDIR /data COPY test/ /data/test data RUN chown -R john:mygroup /data CMD /bin/bash In my test directory, which is copied I have set the file permissions to 770. If I do a su john inside my con...
Christian Metzler
21

votes
4

answer
34k

Views

Dockerfile CMD instruction will exit the container just after running it

I want to setup some configuration when my container starts, for this I am using shell scripts. But my container will exits as soon as my scripts ends, I have tried with -d flag / detached mode but It will never run in detached mode. Below is my Dockerfile FROM ubuntu:14.04 ADD shell.sh /usr/local/b...
Anand Suthar
22

votes
2

answer
32.2k

Views

Docker CentOS image does not auto start httpd

I'm trying to run a simple Docker image with Apache and a PHP program. It works fine if I run docker run -t -i -p 80:80 my/httpd /bin/bash then manually start Apache service httpd start however I cant get httpd to start automatically when running docker run -d -p 80:80 my/httpd Apache will startu...
dwitz
34

votes
2

answer
32.1k

Views

Understanding “VOLUME” instruction in DockerFile

Below is the content of my 'Dockerfile' FROM node:boron # Create app directory RUN mkdir -p /usr/src/app # change working dir to /usr/src/app WORKDIR /usr/src/app VOLUME . /usr/src/app RUN npm install EXPOSE 8080 CMD ['node' , 'server' ] In this file I am expecting 'VOLUME . /usr/src/app' instructi...
refactor
47

votes
2

answer
30.9k

Views

How do I use Docker environment variable in ENTRYPOINT array?

If I set an environment variable, say ENV ADDRESSEE=world, and I want to use it in the entry point script concatenated into a fixed string like: ENTRYPOINT ['./greeting', '--message', 'Hello, world!'] with world being the value of the environment varible, how do I do it? I tried using 'Hello, $ADDRE...
Psycho Punch