41 votes
Accepted

Understanding Docker layers

A docker image is actually a linked list of filesystem layers. Each instruction in a Dockerfile creates a filesystem layer that describes the differences in the filesystem before and after execution ...
user avatar
30 votes
Accepted

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

Docker's EXPOSE documentation addresses this specific point: The EXPOSE instruction does not actually publish the port. It functions as a type of documentation between the person who builds the ...
user avatar
  • 11.1k
23 votes
Accepted

How to change the owner of VOLUME directory in Dockerfile?

As stated in the documentation, VOLUME instruction inherits the directory content and permissions existing in the container, so you can workaround the problem with a dockerfile like this: FROM ubuntu:...
user avatar
  • 11.1k
21 votes
Accepted

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

PHP with nginx is usually done using php-fpm which is a separate processus. Keeping the core idea of docker of one process (see end of answer for more details on this point) per container this makes ...
user avatar
  • 11.1k
17 votes

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

mkdir dir && cd dir && wget http://google.com && rm -rf dir doesn't do what you think it does. Let's break it down: mkdir dir creates dir. cd dir changes directory into it. ...
user avatar
14 votes

Understanding Docker layers

Each instruction you create in your Dockerfile results in a new image layer being created. Each layer brings additional data that are not always part of the resulting image. For example, if you add a ...
user avatar
  • 412
10 votes
Accepted

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

CMD with brackets is contained within an array. Without brackets, the command is executed as /bin/sh -c mysqld. Best practice afaik is to always use brackets.
user avatar
  • 151
10 votes
Accepted

Permission denied within mounted volume inside Docker/Podman container

Thanks to the people here, the solution is quite simple (but not obvious): My GNU/Linux container host has SELinux activated, and that's why I was having permissions problems. The solution is to ...
user avatar
  • 261
7 votes
Accepted

COPY and ZIP files in Dockerfile

Convert the zip file into a gz file before running docker build, possibly in a wrapper script. Or even go one step further, and extract the archive first, then use COPY to copy the resulting folder ...
user avatar
7 votes
Accepted

Docker Images via Container vs Dockerfile

If one uses a Dockerfile then a colleague could also understand what happened (documentation as code). If one runs a container, enters it, runs commits then it would be hard to understand what ...
user avatar
  • 12.6k
7 votes

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

Recent Dockerfile spec allows for multiple FROM statements. https://docs.docker.com/engine/userguide/eng-image/multistage-build/ Using this approach, you can retain your compilation results to a ...
user avatar
6 votes

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

Building on Xiong Chiamiov's answer, which correctly identified the root cause of the problem - the dir reference by relative path when attempting to empty or delete that directory depends on the ...
user avatar
6 votes
Accepted

How to connect to a docker container?

You can get to know if your site is up and running in the following way, Map both the ports of inside container to the host using -p option and try to curl localhost:port Scenario:- Run your ...
user avatar
  • 76
5 votes

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

There is no meaningful benefit that outweighs having to manage two containers. As long as you have a 1:1 relationship between the processes and they serve a single purpose, put them in the same ...
user avatar
  • 1,345
5 votes
Accepted

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

No need to change the Dockerfile. Just define a certain user, e.g. jenkins and a certain uid, e.g. 1000 and ensure the same uid is used when a folder is mounted. ARG user=jenkins ARG uid=1000 # ...
user avatar
  • 12.6k
5 votes

Understanding Docker layers

The RUN statements represent each one layer. Imagine that one downloads a package, installs it and would like to remove it. If one uses three RUN statements then the image size will not shrink as ...
user avatar
  • 12.6k
5 votes
Accepted

Should I chunk my docker images in many small layers instead of one large?

Generally speaking, you want to: Combine multiple related actions/files into a single layer so you don't have tons of layers. Separate out unrelated actions/files which are likely to change ...
user avatar
5 votes
Accepted

How to serve a custom index.html using the stock nginx docker image?

The "official" nginx image has a specific path where it looks for files. You can either copy a file into the image by creating a new image from it or mount your files into this path as a ...
user avatar
4 votes
Accepted

Docker vs CMS - related or a different thing?

Something like puppet would help automate and configure the Docker Container. CMS is configuration/provisioning and Docker is like you said a virtualization platform. You're trying to compare two ...
user avatar
4 votes

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

Actually, one missing point here is the horizontal scalability. There's an article from Jamie Alquiza long time ago addressed this: http://archive.is/pDzz0 In short, you scale your php-fpm ...
user avatar
4 votes

docker container for running automation scripts using jenkins

Yes, you are doing the correct approach. Or rather, "a" correct approach, in your specific circumstance. You are proposing to build the image beforehand, not as part of each individual Jenkins job. ...
user avatar
  • 4,726
4 votes

How to change the owner of VOLUME directory in Dockerfile?

I had a similar problem, this worked for me: Write Docker file with: # Create app layer: FROM python:3.4 # Create app user & group "testuser" with IDs: RUN groupadd -r testuser --gid 1234 &&...
user avatar
  • 141
4 votes
Accepted

Docker: strategy-advise for a rookie

Yes, one would usually have minimal docker images, i.e., one responsibility per image/container, with appropriate networking between them. Yes, images are linear, there is only ever one unbroken line ...
user avatar
  • 4,726
4 votes

Docker ADD always invalidates cache

Check the image history of your two images with docker image history. Pay careful attention to the sha256 checksum of the files being added on the ADD line. Docker performs a checksum on the files, ...
user avatar
  • 2,800
4 votes

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

This is done for automation sake. You can have a universal command that runs docker run -P to start a container and the Dockerfile itself is used to specify which container exposes which port. In case ...
user avatar
  • 5,647
3 votes
Accepted

Scanning fs in a Docker container is (much) slower than on host?

Docker on MacOS runs on a virtual machine (docker-machine), and it's known that docker-machine volume mounts may perform worse than what you'd expect. It becomes worse especially when it comes ...
user avatar
3 votes
Accepted

Why can this ENV not be found when it is defined in one layer using a Dockerfile?

The ENV keyword will be translated to export command (builin of the shell usually), if you remove the multi-line declaration you end up with this equivalent: export A=123 B=$A What happens here is ...
user avatar
  • 11.1k
3 votes

what environment does a build "RUN" run in?

In the Dockerfile, the RUN step is performed during the docker build process. The operating system is shared with the host (containers != VMs). The filesystem and rest of the configuration used to ...
user avatar
  • 2,800
3 votes

When exactly and what for should VOLUME in a Dockerfile be used?

Short version VOLUME instruction and -v dest are used to create unnamed/anonymous volumes, -v scr:dest option is for mapped volume. Long Version Dockerfile's VOLUME does not allow you to specify ...
user avatar
  • 1,689
3 votes
Accepted

Extra none:none images after docker build

Those images are the docker build cache. You need this to be able to quickly rebuild similar images, and to avoid rebuilding unchanged layers which would result in resending those to remote registry ...
user avatar
  • 2,800

Only top scored, non community-wiki answers of a minimum length are eligible