I basically have two docker images: nginx image and a php image, that I want to upload to ECS. Both are run by a docker-compose.
The nginx has a myapp.conf file that I want to copy from somewhere into the container's /etc/nginx/conf.d folder.
Whats the best way to deal with this?
Prepare your own nginx image and use the COPY command.
FROM nginx
COPY myapp.conf /etc/nginx/conf.d
Build it:
docker build -t mynginximg .
and use it in your compose files.
Related
I am trying to understand the Dockerfile of nginx official Docker image. I am focusing on the following lines:
COPY docker-entrypoint.sh /
COPY 10-listen-on-ipv6-by-default.sh /docker-entrypoint.d
I am playing locally with Docker Desktop. If my Dockerfile has only the following line:
FROM nginx
and building my own nginx image, then what is the build context for the Dockerfile of nginx Docker image? My issue is I cannot understand where the files:
docker-entrypoint.sh
10-listen-on-ipv6-by-default.sh
are living and where are they copied from?
Same question is applied to Ubuntu image
The build context is always the directory you give to the build command, and it usually contains the Dockerfile directly in that directory.
docker build ./build-context-directory
# Docker Compose syntax
build: ./build-context-directory
build:
context: ./build-context-directory
The two important things about the context directory are that it is transferred to the Docker daemon as the first step of the build process, and you can never COPY or ADD anything outside the context directory into the image (excepting ADD's ability to download URLs).
When your Dockerfile starts with a FROM line
FROM nginx
Docker includes a pre-built binary copy of that image as the base of your image. It does not repeat the steps in the original Dockerfile, and you do not need the build-context directory of that image to build a new image based on it.
So a typical Nginx-based image hosting only static files might look like
FROM nginx
COPY index.html /usr/share/nginx/html
COPY static/ /usr/share/nginx/html/static/
# Get EXPOSE, ENTRYPOINT, CMD from base image; no need to repeat them
which you can run with only your application's HTML content but not any of the Nginx-specific details you quote in the question.
Seeking help from developers familiar with Wodby container management. The main objective is changing the MIME Types that are gzipped. I'm confused with the documentation for customizing my Nginx container. The documentation:
https://wodby.com/docs/1.0/stacks/drupal/containers/
suggests I copy "/etc/nginx/conf.d/vhost.conf", modify it, deploy it the repo and use an environment variable to include it. My problem is, even if I could find this file, which is not mounted on the server when created via Wodby, it does not appear that I'm actually able to change the MIME types or the default_type as they are already defined in the nginx.conf file.
I have also attempted to modify the Wodby stack to mount the /etc/ directory so that I could manually edit the nginx.conf file if I had to, but that only freezes the deployment.
Any help would be tremendously appreciated.
Two options
clone a repo https://github.com/wodby/nginx/, change the template file /templates/nginx.conf.tmpl as much as you need and build your own image. See Makefile (/Makefile) for the commands they use to build the image themselves. Use this image as the image for your nginx container from docker-compose.
Run a container with the default settings, shell into the container with docker-compose exec nginx sh and copy the nginx file from the container (use cat /etc/nginx/nginx.conf and copy it somewhere). Create a new file locally and mount it via the docker-compose.yml for the nginx container like
volumes:
- ./nginx-custom.conf:/etc/nginx/nginx.conf
I use docker-compose for a simple keycloak container and I've been trying to install a new theme for keycloak.
However I've been unable to copy even a single file to the container usnig a Dockerfile. The Dockerfile and docker-compose.yml are in the same directory
Neither of these commands work or cause any events or warnings in the logs.
COPY test /tmp/
COPY /home/adm/workspace/docker/keycloak-cluster/docker/kctheme/theme/login/. /opt/jboss/keycloak/themes/keycloak/login/
Copying manually with
sudo docker cp test docker_keycloak_1:/tmp
works without any issues.
Quick understanding on Docker.
docker build: Create an image from a Dockerfile
docker run: Create a container from an image.
(you can create yourself the image or use a existing image from docker hub )
Based on what you said, you have 2 options.
Create a new docker image based on the existing one and add the theme.
something like
# Dockerfile
FROM jboss/keycloak
COPY test /tmp/
COPY /home/adm/workspace/docker/keycloak-cluster/docker/kctheme/theme/login/. /opt/jboss/keycloak/themes/keycloak/login/
and then use docker build to create your new image
Volume the theme in the correct directory
using docker-compose volume
version: '3'
services:
keycloak:
image: quay.io/keycloak/keycloak:latest
volumes:
- "./docker/kctheme/theme/login:/opt/jboss/keycloak/themes/keycloak/login"
Files have to be in the same directory or a subdirectory of the directory with your Dockerfile build file if you use COPY, and have to be present at build time. No absolute paths.
/tmp as destination is also a bit tricky, because the startup process of the container might have a /tmp cleanout, which means that you would never see that file in a running container.
FROM nginx:alpine
EXPOSE 80
COPY . /usr/share/nginx/html
Am trying to run an Angular app with the following docker configuration. It does work, but I can't see the files/directory that was suppose to be copied in that location "/usr/share/nginx/html" which is super confusing. The directory only contains the default index.html nginx created.
Does it store it in memory or something since the files are not there but it does fetch my website properly.
Build:
docker build -t appname .
Run:
docker run -d -p 80:80 appname
It seems like the COPY destination path is not the path on disk server but its the path inside the image of the docker. Which explains why i cant see my files on the server disk.
I link my hub.docker.com account with bitbucket.org for automated build. In core folder of my repository exist Dockerfile, which is inside 2 image building steps. If I build images based same Dockerfile in local (i mean in Windows), I get 2 different images. But if I will use hub.docker.com for building, only last image is saved and tagged as "latest".
Dockerfile:
#-------------First image ----------
FROM nginx
#-------Adding html files
RUN mkdir /usr/share/nginx/s1
COPY content/s1 /usr/share/nginx/s1
RUN mkdir /usr/share/nginx/s2
COPY content/s2 /usr/share/nginx/s2
# ----------Adding conf file
RUN rm -v /etc/nginx/nginx.conf
COPY conf/nginx.conf /etc/nginx/nginx.conf
RUN service nginx start
# ------Second image -----------------
# Start with a base image containing Java runtime
FROM openjdk:8-jdk-alpine
# Add a volume pointing to /tmp
VOLUME /tmp
# Make port 8080 available to the world outside this container
EXPOSE 8080
# The application's jar file
ARG JAR_FILE=jar/testbootstap-0.0.1-SNAPSHOT.jar
# Add the application's jar to the container
ADD ${JAR_FILE} test.jar
# Run the jar file
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/test.jar"]
Anybody did this before or its not possible?
PS: There only one private repository for free use, may be this is main reason.
Whenever you specify a second FROM in your Dockerfile, you start creating a new image. That's the reason why you see only the last image being saved and tagged.
You can accomplish what you want by creating multiple Dockerfiles, i.e. by creating the first image in its Dockerfile and then using that to create the second image - all of it using docker-compose to co-ordinate between the containers.
I found some walk-around for this problem.
I separate docker file to two file.
1.docker for ngix
2.docker for java app
In build settings set this two files as dockerfile and tag with different tags.
After building you have one image but versions is define as image name. For example you can use
for nginx server youraccount/test:nginx
for app image youraccount/test:java
I hope this will be no problem in future processes.