Docker : image build failed - apache

when building docker apache image, the building fail in this step :
Step n/m : COPY httpd-foreground /usr/local/bin/
ERROR: Service 'apache' failed to build: COPY failed: stat
/var/lib/docker/tmp/docker-builder511740141/httpd-foreground: no such
file or directory
this is my docker_compose.yml file
version: '3'
services:
mysql:
image: mysql:5.7
container_name: mysql_octopus_dev
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: app
MYSQL_USER: root
MYSQL_PASSWORD: root
apache:
build: .
container_name: apache_octopus_dev
volumes:
- .:/var/www/html/
ports:
- "8000:80"
depends_on:
- mysql
this is my docker file
FROM debian:jessie-backports
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
#RUN groupadd -r www-data && useradd -r --create-home -g www-data www-data
...
COPY httpd-foreground /usr/local/bin/
EXPOSE 80
CMD ["httpd-foreground"]
any help please?

Paths in a Dockerfile are always relative to the the context directory. The context directory is the positional argument passed to docker build (often .).
I should place the httpd-foreground file in the same folder of dockerfile.
From : https://github.com/docker/for-linux/issues/90

Related

Docker Nginx with React and Laravel

So I want to have a single Nginx web server serving both frontend and backend with Docker.
Here is my docker-compose:
version: "3.8"
services:
db: #mysqldb
image: mysql:5.7
container_name: ${DB_SERVICE_NAME}
restart: unless-stopped
environment:
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_USER: ${DB_USERNAME}
SERVICE_TAGS: dev
SERVICE_NAME: mysql
ports:
- $MYSQLDB_LOCAL_PORT:$MYSQLDB_DOCKER_PORT
volumes:
- ./docker-compose/mysql:/docker-entrypoint-initdb.d
networks:
- backend
mrmfrontend:
build:
context: ./mrmfrontend
args:
- REACT_APP_API_BASE_URL=$CLIENT_API_BASE_URL
- REACT_APP_BACKEND_ENDPOINT=$REACT_APP_BACKEND_ENDPOINT
- REACT_APP_FRONTEND_ENDPOINT=$REACT_APP_FRONTEND_ENDPOINT
- REACT_APP_FRONTEND_ENDPOINT_ERROR=$REACT_APP_FRONTEND_ENDPOINT_ERROR
- REACT_APP_CUSTOMER=$REACT_APP_CUSTOMER
- REACT_APP_NAME=$REACT_APP_NAME
- REACT_APP_OWNER=""
ports:
- $REACT_LOCAL_PORT:$REACT_DOCKER_PORT
networks:
- frontend
nginx:
image: nginx:alpine
container_name: backend-nginx
restart: unless-stopped
ports:
- 8000:80
volumes:
- ./MRMBackend:/var/www
- ./docker-compose/nginx/backend:/etc/nginx/conf.d/
networks:
- backend
- frontend
app:
build:
args:
user: admin
uid: 1000
context: ./MRMBackend
dockerfile: Dockerfile
image: backend
container_name: backend-app
restart: unless-stopped
working_dir: /var/www/
volumes:
- ./MRMBackend:/var/www
networks:
- backend
volumes:
db:
networks:
frontend:
driver: bridge
backend:
driver: bridge
And here's the Dockerfile for the frontend:
FROM node:16.13.0 as build-stage
WORKDIR /app
COPY package.json ./
COPY package-lock.json ./
COPY ./ ./
RUN npm i
ARG REACT_APP_API_BASE_URL
ARG REACT_APP_BACKEND_ENDPOINT
ARG REACT_APP_FRONTEND_ENDPOINT
ARG REACT_APP_FRONTEND_ENDPOINT_ERROR
ARG REACT_APP_CUSTOMER
ARG REACT_APP_NAME
ENV REACT_APP_API_BASE_URL=$REACT_APP_API_BASE_URL
ENV REACT_APP_BACKEND_ENDPOINT=$REACT_APP_BACKEND_ENDPOINT
ENV REACT_APP_FRONTEND_ENDPOINT = $REACT_APP_FRONTEND_ENDPOINT
ENV REACT_APP_FRONTEND_ENDPOINT_ERROR = $REACT_APP_FRONTEND_ENDPOINT_ERROR
ENV REACT_APP_CUSTOMER=$REACT_APP_CUSTOMER
ENV REACT_APP_NAME=$REACT_APP_NAME
ENV GENERATE_SOURCEMAP=false
RUN npm run build
The problem is that the frontend container can't seem to start. It exit always at startup.
From my understanding I should copy the build content of the build-stage into the nginx folder "/usr/share/nginx/html" but how can I do it from the docker-compose file?
Just using volumes won't work. I need nginx in the docker-compose because it's also serving the backend.
Please note that the backend is working correctly.
UPDATE
My first approach was to use a Dockerfile for the frontend where I copied the content of the build directly into an Nginx image
# Stage 1
FROM node:16.13.0 as build-stage
WORKDIR /app
COPY package.json ./
COPY package-lock.json ./
COPY ./ ./
RUN npm i
ARG REACT_APP_API_BASE_URL
ARG REACT_APP_BACKEND_ENDPOINT
ARG REACT_APP_FRONTEND_ENDPOINT
ARG REACT_APP_FRONTEND_ENDPOINT_ERROR
ARG REACT_APP_CUSTOMER
ARG REACT_APP_NAME
ENV REACT_APP_API_BASE_URL=$REACT_APP_API_BASE_URL
ENV REACT_APP_BACKEND_ENDPOINT=$REACT_APP_BACKEND_ENDPOINT
ENV REACT_APP_FRONTEND_ENDPOINT = $REACT_APP_FRONTEND_ENDPOINT
ENV REACT_APP_FRONTEND_ENDPOINT_ERROR = $REACT_APP_FRONTEND_ENDPOINT_ERROR
ENV REACT_APP_CUSTOMER=$REACT_APP_CUSTOMER
ENV REACT_APP_NAME=$REACT_APP_NAME
#avoid javascript out of memory
ENV GENERATE_SOURCEMAP=false
RUN npm run build
# Stage 2
FROM nginx:1.17.0-alpine
COPY --from=build-stage /app/build /usr/share/nginx/html
EXPOSE $REACT_DOCKER_PORT
CMD nginx -g 'daemon off;'
But in this way I think I'm deploying two Nginx. One in the Dockerfile and one in the Docker-compose. Am I right?
#federico-arona
As stated in my comment: If you want to have 1 nginx you need to share or copy the files from the container that is building the app.
Based on your requirements and what you wanted to accomplish. The best solution is named volumes, as they can be shared across containers.
They are the preferred mechanism for persisting data generated by and used by Docker containers. Plus you can manage volumes using Docker CLI commands and the Docker API. The Official docs show other benefits and additional information on how to use them.
I mostly use Docker multi-build to configure my FE app. Hope this might help you!
FROM node:16.13.0 as build-stage
WORKDIR /app
COPY package.json ./
COPY package-lock.json ./
COPY ./ ./
RUN npm install
RUN npm run dev
#Build Files
FROM nginx:1.19.10-alpine
COPY nginx-conf /etc/nginx/conf.d/default.conf
COPY --from=build /app /home/ubuntu/app/dist
you can use default nginx configuration.

Docker httpd:alpine image exits with code 1

I am trying to run some basic html pages using httpd docker image.
Dockerfile
FROM httpd:alpine
COPY ./views /usr/local/apache2/htdocs/ # where my html pages stored
COPY httpd.conf /usr/local/apache2/conf/httpd.conf
RUN httpd -v
EXPOSE 7074
httpd.conf
ServerName localhost
Listen 7074
LoadModule mpm_event_module modules/mod_mpm_event.so
docker-compose
version: '3'
frontend_image:
image: frontend_image
build:
context: ./frontend_image
dockerfile: Dockerfile
network_mode: "host"
env_file: "./api.env"
depends_on:
- apigateway
Then : sudo docker-compose up --build
RUN httpd -v gives:
Server version: Apache/2.4.43 (Unix)
Server built: Apr 24 2020 15:46:58
But
Project_frontend_image_1 exited with code 1
How can I add an Entry-point to httpd, as I do not have apachectl2 in /usr/sbin.
refered : Docker run Exited 1 httpd
Edit :
I have tried docker run -dit --name my-apache-app -p 7575:80 -v "$PWD":/usr/local/apache2/htdocs/ httpd:2.4
and it works.
It seems this is a problem with httpd.conf file rather than the Docker image.
As you can run docker run -dit --name my-apache-app -p 7575:80 -v "$PWD":/usr/local/apache2/htdocs/ httpd:2.4 and access to apache service.
Run above command and login to running container : sudo docker exec -it container_id /bin/sh
cat /usr/local/apache2/conf/httpd.conf
Copy the content and past in your httpd.conf, change port.
No need to add CMD[""] things as httpd:alpine base image does it.
Just COPY httpd.conf /usr/local/apache2/conf/httpd.conf in Dockerfile.
This is the script executed by default by the httpd alpine image:
2.4/alpine/httpd-foreground
#!/bin/sh
set -e
# Apache gets grumpy about PID files pre-existing
rm -f /usr/local/apache2/logs/httpd.pid
exec httpd -DFOREGROUND "$#"
Try and add an echo "test" before and after the rm command to check that:
the CMD script is actually called
the rm command is not the one causing an error (and an exit of the script with status 1)
docker-library/httpd issue 127 mentions a similar issue, solved with the Apache ErrorLog directive (presumably similar to one used in issue 133, with a mounted httpd-vhosts.conf.
I have tried docker run -dit --name my-apache-app -p 7575:80 -v "$PWD":/usr/local/apache2/htdocs/ httpd:2.4 and it works.
Then modify your docker-compose.yml to include the same mount (see documentation):
frontend_image:
image: frontend_image
volumes:
- ./:/usr/local/apache2/htdocs/
build:
context: ./frontend_image
dockerfile: Dockerfile
network_mode: "host"
env_file: "./api.env"
depends_on:
- apigateway

Docker don't have permission on this server

I have a dockerfile and docker-compose.yml.
I don't understand why i don't have the permission ...
I have also a index.php in my public folder
Dockerfile:
FROM php:7.2-apache
RUN apt-get update && docker-php-ext-install pdo_mysql
Docker-compose.yml:
version: "3"
services:
php:
build: './image/'
volumes:
- ./src:/var/www/html/
ports:
- '30000:80'
adminer:
image: adminer
ports:
- '40000:8080'
db:
image: mariadb
environment:
- MYSQL_ROOT_PASSWORD=secret
- MYSQL_USER=root
- MYSQL_PASSWORD=root
- MYSQL_DATABASE=meetup
Folders:
meetup
app
bin
get_started
image
dockerfile
public
index.php
src
templates
docker-compose.yml
Based on your comment, it simply looks like the root directory of the Apache does not contain index.php.
You should do one of these:
Either move the index.php from your public folder to your src folder
Or, change the mount in the docker-compose from ./src:/var/www/html to ./public:/var/www/html (in any case, the trailing slash is not needed).

How to copy files from docker container to host using docker-compose in docker-machine

I have reports generated in gradle container for my selenium tests, I am trying to copy the files from docker container to local host. As a work around, I have used docker cp to copy files from container to my local and it works. How to achieve it with docker-compose volumes.
Below is my docker-compose.yml
version: "3 "
services:
selenium-hub:
image: selenium/hub
container_name: selenium-hub_compose
ports:
- "4444:4444"
chrome:
image: selenium/node-chrome-debug
container_name: selenium-chrome
depends_on:
- selenium-hub
ports:
- "5900"
environment:
- http_proxy=http://x.x.x.x:83
- https_proxy=http://x.x.x.x:83
- HUB_HOST=selenium-hub
- HUB_PORT=4444
gradle:
image: gradle:jdk8
container_name: selenium-gradle
build:
context: .
dockerfile: dockerfile
I run the command docker-compose up -> it runs the selenium tests and generates the report in the container.
Can anyone help on this?
The normal way to pass data from container to host is using docker volumes.
In short you specify a host directory and map it to the directory inside container. And that directory should be used to save your test reports
services:
selenium-hub:
image: selenium/hub
container_name: selenium-hub_compose
ports:
- "4444:4444"
volumes:
- ./path/to/report/folder:/host/reports
See docker documentation
https://docs.docker.com/compose/compose-file/#/volumes-volumedriver
Similar question:
How do I mount a host directory as a volume in docker compose
Power off the machine in Virtual box -> Change the Advanced settings in Virtual box
Goto Shared Folders in Virtual box
Give Path :: C:\DockerResults : Give a logical name for the Folder name
Restart the machine in DockerTerminal with the below command
docker-machine restart default
After machine is started open the Virtual box
Create a directory in the Virtual machine : sudo mkdir /Results
Mount the directory to the local windows machine by executing the below command in virtual box:
Sudo mount –t vboxsf DockerResults /Results
Add volumes as below in docker-compose file
volumes:
- /DockerResults:/home/Reports/

DRY docker-compose

I'm trying to find a more DRY way to use docker-compose env.
docker-compose-base.yml
base:
image: reactjs_web
volumes:
- src:/reactjs/src
- bin/server:/reactjs/bin/server
- config:/reactjs/config
docker-compose-prod.yml
svr:
extends:
file: docker-compose-base.yml
service: base
command: npm run prod:deploy
ports:
- "8081:8081"
environment:
NODE_ENV: production
PORT: "8081"
CLTPORT: "8082"
clt:
extends:
file: docker-compose-base.yml
service: base
command: npm run prod:deploy:clientside
ports:
- "8082:8082"
environment:
NODE_ENV: production
PORT: "8082"
The ports and the env port are equals
Is there a way to reference the clt port to the svr container ?
Docker Environment File
Use a .env file and reference it in both containers. This will ensure you only need to store these settings in a single location.
Compose supports declaring default environment variables in an environment file named .env placed in the folder docker-compose command is executed from (current working directory).
Compose expects each line in an env file to be in VAR=VAL format. Lines beginning with # (i.e. comments) are ignored, as are blank lines.
Compose File Integration:
env_file: .env
env_file:
- ./common.env
- ./apps/web.env
- /opt/secrets.env
Docker Compose File Reference - env_file
Docker Compose Environment File Documentation
You can use environment variable inside docker-compose.
svr:
extends:
file: docker-compose-base.yml
service: base
command: npm run prod:deploy
ports:
- ${CLTPORT}:${PORT}
environment:
NODE_ENV: production
clt:
extends:
file: docker-compose-base.yml
service: base
command: npm run prod:deploy:clientside
ports:
- ${CLTPORT2}:${PORT2}
environment:
NODE_ENV: production
run docker-compose like:
CLTPORT=8082 PORT=8081 CLTPORT2=8081 PORT2=8082 docker-compose -f docker-compose-prod.yml up
Of course change your port variables as you need.
You can reference an environment variable to solve this
https://github.com/docker/compose/issues/1377