Skip to main content

Questions tagged [dockerfile]

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

Filter by
Sorted by
Tagged with
35 votes
4 answers
169k views

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

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 ...
030's user avatar
  • 13.2k
33 votes
3 answers
8k views

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-...
alecxe's user avatar
  • 849
31 votes
2 answers
87k views

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 ...
kenorb's user avatar
  • 7,911
30 votes
4 answers
13k views

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 ...
CarlosAS's user avatar
  • 435
28 votes
2 answers
13k views

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 ...
Alexander Bird's user avatar
9 votes
1 answer
1k views

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 ...
030's user avatar
  • 13.2k
7 votes
1 answer
25k views

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 ...
Dougui's user avatar
  • 173
6 votes
3 answers
4k views

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 ...
Sylvain Leroux's user avatar
6 votes
1 answer
35k views

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 ...
Ta Mu's user avatar
  • 6,782
6 votes
1 answer
984 views

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 ...
Tran Triet's user avatar
5 votes
3 answers
27k views

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 ...
Valter Silva's user avatar
5 votes
1 answer
622 views

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 ...
Glenak1911's user avatar
5 votes
2 answers
13k views

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 ...
AdrianDeWinter's user avatar
5 votes
2 answers
388 views

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 ...
dev2d's user avatar
  • 151
5 votes
2 answers
482 views

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 ...
Zeinab Abbasimazar's user avatar
4 votes
2 answers
198 views

Docker vs CMS - related or a different thing?

I am new to DevOps and I am trying to catch the techniques and their names and meanings. I looked wikipedia explanations on Puppet (a Configuration Management System example) and that of Docker. ...
mico's user avatar
  • 525
4 votes
1 answer
820 views

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

When I build docker image for existing applications I try to use as few layers as possible and clean up any unwanted files. For example building an image for moodle: # Dockerfile for moodle instance. ...
Dimitrios Desyllas's user avatar
4 votes
1 answer
2k views

Docker ADD always invalidates cache

I've got problem with my Dockerfile. After building an image it is pushed to repository as cache-image, so on next builds I can pull it and use with --cache-from. Problem is that build stops using ...
Blejwi's user avatar
  • 151
4 votes
1 answer
107 views

Docker: strategy-advise for a rookie

I am VERY new to Docker and I looking for a confirmation of my views and my usage of Docker in my use-cases. I'll try it with examples: I have a T3 application. Every tier is a basic requirement (...
chris01's user avatar
  • 143
4 votes
1 answer
372 views

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

When writing a Dockerfile, I do have the option of specifying volumes, such as: VOLUME /var/www But even without this declaration I am able to mount volumes to this directory and other places, e.g. ...
Thomas Luzat's user avatar
4 votes
1 answer
1k views

How do I prevent service A from being placed in the same node as service B in Docker Swarm?

From the docs, I could only find information about placement restrictions based on node attributes, likes labels and its role. However, I couldn't find how to configure placement based on the services ...
ivarec's user avatar
  • 183
4 votes
2 answers
210 views

How to automate the magento2 installation process too via docker

This is what I have accomplished up to now. Written a docker file where I have done the following and for now I have not used the docker compose. Used alpine as base Os setup nginx setup php-fpm ...
Tara Prasad Gurung's user avatar
3 votes
2 answers
687 views

What is the difference between RUN and CMD in a Dockerfile?

I am going to change my permission of files to 600. The following command works perfectly. RUN /bin/bash -c 'chmod 600 /root/.ssh/config' But this one failed CMD /bin/bash -c 'chmod 600 /root/.ssh/...
rj487's user avatar
  • 143
3 votes
1 answer
355 views

Multiple apps (microservices) and one proxy (nginx) docker-compose configuration/architecture

Having the following architecture: Microservice 1 + DB (microservice1/docker-compose.yml) Microservice 2 + DB (microservice2/docker-compose.yml) Proxy (proxy/docker-compose.yml) Which of the ...
Mr. Mars's user avatar
  • 163
3 votes
1 answer
4k views

How to connect to host during a Docker build?

I have a Dockerfile which I want to run some tests inside of as part of a multistage build. The tests attempt to make a connection to localhost, however it appears that they're not able to connect to ...
Madden's user avatar
  • 213
3 votes
2 answers
1k views

Unable to build Image as it is asking some input

I am trying to create an Image which will run ftp server on centos. Dockerfile content is as below: FROM centos RUN \ yum update -y && \ yum install vsftpd -y EXPOSE 21 CMD vsftpd -...
Puneet Dixit's user avatar
3 votes
1 answer
16k views

npm not found but installed from the shell script file in Dockerfile

I have a following Dockerfile: FROM ubuntu:18.04 RUN mkdir app && cd app WORKDIR app/ RUN apt-get update && apt-get install -y \ software-properties-common \ curl \ sudo ...
Leon Ma's user avatar
  • 33
3 votes
2 answers
139 views

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

When the following Dockerfile: ENV A=123 \ B=$A RUN echo $B is run, it results in: Step 2/2 : RUN echo $B ---> Running in x ---> y Removing intermediate container z When two ENV ...
030's user avatar
  • 13.2k
3 votes
3 answers
6k views

Jenkins Dockerfile declarative pipelines: getting the built image tag

I'm trying to get the image tag generated with the help of the dockerfile agent in Jenkins declarative pipelines. This Jenkinsfile is incomplete though, because I still need the deployment steps. ...
Attila Szeremi's user avatar
3 votes
1 answer
2k views

Dockerfile COPY command with three input parameters

I've encountered a Multi-stage Build example, where the first stage builds a ngnix server, and the second stage creates a ngnix service from that image. The second stage looks like this: ... # ...
orberkov's user avatar
  • 195
3 votes
1 answer
156 views

Why screen folder in /var/run disappears in Docker container after running Ansible playbook?

Files I've got the following Dockerfile: FROM ansible/ansible:ubuntu1604py3 ENV DEBIAN_FRONTEND noninteractive RUN pip3 install ansible RUN printf '[local]\r\nlocalhost ansible_python_interpreter="...
kenorb's user avatar
  • 7,911
3 votes
1 answer
879 views

Adding default external network in docker-compose

I am trying to learn docker and understanding docker-compose As I was trying out the external network section: networks: default: external: name: my-pre-existing-network I understand ...
Vipin Menon's user avatar
2 votes
2 answers
19k views

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

How do I serve static content from the default nginx docker image? Given: root@mordor:~# root@mordor:~# docker image ls nginx REPOSITORY TAG IMAGE ID CREATED ...
Nicholas Saunders's user avatar
2 votes
3 answers
11k views

How can I get the Docker target platform inside the Build Environment / Dockerfile

I'm doing multi-platform builds with buildx and would like to know if there is a way to determine what platform is currently being build so I can avoid certain steps for certain environments. For ...
Tracker1's user avatar
  • 123
2 votes
3 answers
2k views

How to automatically update Docker containers in development?

What is the best way to use Docker in development so that a container is automatically updated each time you make a change to the codebase?
leandre's user avatar
  • 21
2 votes
1 answer
6k views

Dockerfile parse error line 5: unknown instruction: -ESSENTIAL

this is my dockerfile ; FROM ubuntu:16.04 MAINTAINER James Turnbull "[email protected]" ENV REFRESHED_AT 2016-06-01 RUN apt-get update -yqq; apt-get -yqq install ruby ruby-dev build -essential ...
theSeeker's user avatar
  • 123
2 votes
1 answer
126 views

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

Is scanning/searching the filesystem slower in a Docker container, than on the host? Seems a lot slower from my testing and sometimes I get an EIO scan error. Specifically I am scanning a read-only (:...
Alexander Mills's user avatar
2 votes
1 answer
44 views

why use multiple From instructions in multistage build?

I'm new to Docker, sorry if my question sounds dumb. below is a dockerfile from a textbook shows how multistage build works: FROM diamol/base AS build-stage RUN echo 'Building...' &...
amjad's user avatar
  • 123
2 votes
1 answer
541 views

What is the best way to put on a repository for a docker image with multiple tags?

I've seen a lot of repositories with Docker images and I think (correct me if my guessing is wrong) that the projects that handle a docker image with multiple tags can be grouped into three groups: ...
gvgramazio's user avatar
2 votes
2 answers
2k views

Preinstall packages for a nodejs Docker Image according to package.json

I would like to prepare a Docker image for a nodejs project. The developers use package.json to list their node module dependencies. I would like to prepare the Docker image (as base on the Dockerfile)...
orberkov's user avatar
  • 195
2 votes
1 answer
266 views

Why can I build this image from Docker for Mac but not on Docker CE for Ubuntu?

Here's my Dockerfile: FROM php:5-fpm RUN apt-get update RUN apt-get install -y php5-mysql RUN apt-get install -y php5-xdebug RUN apt-get install -y php5-mcrypt RUN apt-get install -y php5-gd When I ...
skb's user avatar
  • 23
2 votes
1 answer
664 views

Docker Compose: How do you build an image while running another container?

I'm trying to build a Nuxt 3 application using docker compose. However, I'm having trouble with docker compose and dockerfile configuration. Context To give background on the project that I'm working ...
Zerro97's user avatar
  • 21
2 votes
1 answer
5k views

Jenkins does not seem to be running inside a container

I am getting an error while running the Jenkins file tp build and push the docker image into docker hub . you can reveiw my code github : https://github.com/iakshaykr/webapp.git (using jenkins_pipe ...
Akshay Kumar's user avatar
2 votes
1 answer
3k views

running a phpUnit test within a docker container

i want to run a specific version of phpUnit WITHIN a docker container. This container will use a specific version of php. i.e php:5.6-apache Its a lareval application. i have install phpunit via ...
Paul Kendal's user avatar
2 votes
1 answer
93 views

Built codebase doesnt appear after deploying

I'm packaging and shipping a custom code base of Wordpress with a Dockerfile in to my private container registry. Dockerfile: FROM wordpress:latest ADD . /var/www/html Then on the deployment server I ...
inckka's user avatar
  • 141
2 votes
1 answer
1k views

What are the correct volume maps for zabbix running on Docker?

I want to run zabbix inside Docker and there are images for MySQL, Nginx and zabbix server ready to go. I know that to keep the containers stateless I need to map a volume on the host to the ...
Wings's user avatar
  • 203
2 votes
1 answer
1k views

Can't change ownership of folders and files in Docker containers

I am having these two dockerfiles which in both I am adding the command RUN chown -R www-data:www-data /var/www/html to change the ownership to www-data user. The containers seems to build ...
ltdev's user avatar
  • 121
2 votes
0 answers
341 views

Run commands on docker container and sync automatically with host

I Dockerkized a MENN(Nextjs) stack App, now everything works fine. I run into issues when i need to install npm packages. let me first show you the structure src/server/Dockerfile FROM node:14-alpine ...
uneeb meer's user avatar
2 votes
2 answers
1k views

Building a docker container with multiple conda envs

As a novice to the technology I have only a basic knowledge regarding how to build and deploy a docker so i was hoping someone could provide some help. The situation is the following: I need to create ...
bboy's user avatar
  • 21
2 votes
0 answers
2k views

Can not find save handler 'redis' - session startup failed - for PHP

I am getting this error while loading index.php file. Warning: session_start(): Cannot find save handler 'redis' - session startup failed in /var/www/html/index.php on line 2 My index.php code ...
Gaurav Bhaskar's user avatar