Questions tagged [dockerfile]

For questions about Dockerfiles - text files containing instructions to build Docker container images.

From Dockerfile reference:

Docker can build images automatically by reading the instructions from a Dockerfile. A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build users can create an automated build that executes several command-line instructions in succession.

119 questions
36
votes
4 answers

How to remove directories and files in another layer using Docker?

Why this question? The reason for posting this Q&A is that sometimes certain software is required to compile software in a docker image. Once compiled, these packages are superfluous and should be removed in order to reduce the image size. In some…
030
  • 13,383
  • 17
  • 76
  • 178
33
votes
3 answers

Understanding Docker layers

We have the following block in our Dockerfile: RUN yum -y update RUN yum -y install epel-release RUN yum -y groupinstall "Development Tools" RUN yum -y install python-pip git mysql-devel libxml2-devel libxslt-devel python-devel openldap-devel…
alecxe
  • 849
  • 1
  • 16
  • 36
32
votes
2 answers

How to change the owner of VOLUME directory in Dockerfile?

I've got the following Dockerfile: FROM ubuntu:xenial RUN useradd -d /home/ubuntu -ms /bin/bash -g root -G sudo -p ubuntu ubuntu WORKDIR /home/ubuntu USER ubuntu VOLUME /opt/myvolume Which I built it: $ docker build -t vol-test . Sending build…
kenorb
  • 8,011
  • 14
  • 43
  • 80
30
votes
4 answers

What are the advantages of dockerizing nginx and php in different containers?

I just started working with Docker and Kubernetes and I've been watching a lot of stacks, in which some people build nginx+php in a single image and some build an image with nginx and another one with php (mounting the same path and enclosing both…
CarlosAS
  • 435
  • 1
  • 5
  • 9
28
votes
2 answers

Why use EXPOSE in Dockerfile -- since you can bind to all ports anyways

I can docker run -p 3000:3000 image without EXPOSEing that port in the container (see below). If that's true, then why bother putting EXPOSE in the Dockerfile? Is it just for communication to image users? Because I don't know of a functional reason…
Alexander Bird
  • 395
  • 1
  • 3
  • 6
9
votes
1 answer

What is the difference between using brackets (`[` `]`) and just specifying the command in the CMD option in Dockerfiles?

Why does CMD ["mysqld"] result in: db_1 | 2017-05-14T16:34:11.829163Z 0 [Note] mysqld (mysqld 5.7.18) starting as process 1 ... db_1 | 2017-05-14T16:34:11.833159Z 0 [Note] InnoDB: PUNCH HOLE support available db_1 | 2017-05-14T16:34:11.833190Z…
030
  • 13,383
  • 17
  • 76
  • 178
8
votes
1 answer

Change owner of files created inside a Docker container without changing the Dockerfile

When I create a file inside a container with docker-compose run web touch test the file owns to root:root. I want to change it to be $USER without to use chown. I'm aware of the --user option but it requires to have the user created on the…
Dougui
  • 183
  • 1
  • 1
  • 5
6
votes
3 answers

In a Dockerfile, is there a way to avoid copying files to make them accessible to the RUN command?

I need to build a Docker image containing a pre-populate a database. For now, I am using the following commands in our Dockerfile: COPY db-dump.gz /tmp RUN zcat /tmp/db-dump.gz | mysql But is there a way to achieve the same result without copying…
Sylvain Leroux
  • 1,660
  • 2
  • 15
  • 27
6
votes
1 answer

COPY and ZIP files in Dockerfile

Using a COPY statement creates a new image layer, right? COPY files/foo.zip /tmp/ Now, to save space I could take the ADD statement... for a GZ arhive. But ADD does not support automatic extraction of ZIP files. So the foo.zip will be dangling…
Ta Mu
  • 6,792
  • 5
  • 43
  • 83
6
votes
1 answer

How to pin OS package versions in Docker image

Scenario For obvious reasons I believe that every package installed in a Docker image should have their version nailed down. That's why in our Dockerfile we always enforce the OS package manager to install a specific version of a package. For…
Tran Triet
  • 879
  • 3
  • 11
  • 21
5
votes
3 answers

How to connect to a docker container?

I have the following Dockerfile: FROM ubuntu:latest MAINTAINER Valter Silva RUN apt-get update RUN apt-get install -y apache2 ADD index.html /var/www/html/ CMD /usr/sbin/apache2ctl -D FOREGROUND EXPOSE 22 EXPOSE 80 This is how I build my…
Valter Silva
  • 209
  • 1
  • 2
  • 6
5
votes
1 answer

Docker Images via Container vs Dockerfile

Pardon the dumb questions, but I've been learning about Docker and container technologies and I was learning about using Dockerfiles to specify build instructions for an image, and how each instruction creates a layer that will impact the overall…
Glenak1911
  • 175
  • 5
5
votes
2 answers

Make use of CIs as Maven Repository in order to use it for building Docker images without including dependencies

I am trying to make images from our company Maven based applications. These apps are using some libraries which are included in a Maven repository, but fills a lot of disk space. They also have some dependencies which should be downloaded. I have…
5
votes
2 answers

DNS resolution fails when container is started via docker-compose

I recently decided to try out windows containers and i am using my private minecraft server for that purpose (as a hobby project). I have an image prepared, based on Windows Server Core 2022. When i start the container manually, it works…
AdrianDeWinter
  • 91
  • 1
  • 1
  • 7
5
votes
2 answers

Best Practice for writing DockerFile

I have mostly seen people using following type of pipeline steps(it varies, but in general this is the flow of steps I have observed) Process: clone repo -> build -> test -> create docker image -> push binary to artifactory -> push image to docker…
dev2d
  • 151
  • 3
1
2 3 4 5 6 7 8