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
Related
New to Docker and trying to get the cgi-bin working in a httpd image. My Dockerfile is as follows. The SED line adds the perl location to the first line of the example script that comes with the image:
FROM httpd:2.4.46
RUN sed -i '1c#!/usr/bin/perl' /usr/local/apache2/cgi-bin/printenv
I then build and run with:
docker build -t my-apache2 .
docker run -dit --name my-running-app -p 8080:80 my-apache2
I then navigate to localhost:8080/cgi-bin/printenv but instead of the script executing I get the code displayed as text. It appears the httpd image comes with ScriptAlias enabled by default. Any ideas please?
You also need to enable mod_cgid
FROM httpd:2.4.46
RUN sed -i '1c#!/usr/bin/perl' /usr/local/apache2/cgi-bin/printenv
RUN chmod +x /usr/local/apache2/cgi-bin/printenv
CMD httpd-foreground -c "LoadModule cgid_module modules/mod_cgid.so"
When i'm running sudo docker-compose up inside my dir, i get this error. I'm trying to make a container, that host a php website, where you can do whoami on it.
Thanks
(13)Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:80
| no listening sockets available, shutting down
| AH00015: Unable to open logs
Dockerfile:
FROM ubuntu:16.04
RUN apt update
RUN apt install -y apache2 php libapache2-mod-php
RUN useradd -d /home/cp/ -m -s /bin/nologin cp
WORKDIR /home/cp
COPY source .
USER cp
ENTRYPOINT service apache2 start && /bin/bash
docker-compose.yml
version: '2'
services:
filebrowser:
build: .
ports:
- '8000:80'
stdin_open: true
tty: true
volumes:
- ./source:/var/www/html
- ./logs:/var/log/apache2
There's a long-standing general rule in Unix-like operating systems that only the root user can open "low" ports 0-1023. Since you're trying to run Apache on the default HTTP port 80, but you're running it as a non-root user, you're getting the "permission denied" error you see.
The absolute easiest answer here is to use a prebuilt image that has PHP and Apache preinstalled. The Docker Hub php image includes a variant of this. You can use a simpler Dockerfile:
FROM php:7.4-apache
# Has Apache, mod-php preinstalled and a correct CMD already,
# so the only thing you need to do is
COPY source /var/www/html
# If you want to run as a non-root user, you can specify
RUN useradd -r -U cp
ENV APACHE_RUN_USER cp
ENV APACHE_RUN_GROUP cp
With the matching docker-compose.yml
version: '3' # version 2 vs 3 doesn't really matter
services:
filebrowser:
build: .
ports:
- '8000:80'
volumes:
- ./logs:/var/log/apache2
If you want to build things up from scratch, the next easiest option would be the Apache User directive: have your container start as root (so it can bind to port 80) but then instruct Apache to switch to the unprivileged user once it's started up. The standard php:...-apache image has an option to do this on its own which I've shown above.
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
I've started with IBM's image:
registry.ng.bluemix.net/ibmnode:latest
It's Ubuntu 14.04, I then add Apache2 on, do some file copies of my site, and then EXPOSE 443. Lastly, I invoke a bash script with the following:
#!/bin/bash
set -e
rm -f /usr/local/apache2/logs/httpd.pid
exec /usr/sbin/apache2ctl -DFOREGROUND
When I run the container locally, it works fine and serves up what I need. When BlueMix builds from the Dockerfile, that works without error. Then deploys to a container successfully. Immediately after deploy, the container registers as 'STOPPED'. Restarting brings it up and then back down within a few seconds. 'cf ic logs my-process-id' doesn't show any feedback.
Other things I've tried:
ENTRYPOINT ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
Using service apache2 restart
Dockerfile:
FROM registry.ng.bluemix.net/ibmnode:latest
RUN apt-get install -y apache2
RUN apt-get install -y nano
# ADD SSL
RUN a2enmod ssl
RUN a2enmod proxy_http
WORKDIR /var/www/dist
RUN mv ./* /var/www/html
COPY docker/httpd-foreground.sh /usr/local/bin/
EXPOSE 443
CMD ["httpd-foreground.sh"]
httpd-foreground.hs:
#!/bin/bash
set -e
rm -f /usr/local/apache2/logs/httpd.pid
exec /usr/sbin/apache2ctl -DFOREGROUND
What you are trying to do is getting node image, installing apache and overriding the command, and trying to run in the foreground. This is not really a good way to run a apache container on bluemix.
You should do something like this:
1. Follow information in here to pull the httpd image to your local, push the local image to your bluemix name space.
- docker pull httpd:2.4
- docker tag httpd:2.4 registry.ng.bluemix.net//httpd
- docker push registry.ng.bluemix.net//http
2. Once the image is pushed to your namespace, you can create custom image with your Dockerfile, note that I assume you have your website content in public-html folder
FROM registry.ng.bluemix.net//httpd:2.4 COPY ./public-html/
/usr/local/apache2/htdocs/ EXPOSE 80
Build your image
cf ic build --tag myhttp .
Run the container:
cf ic run --name myhttp -p 80 registry.ng.bluemix.net/<yourNameSpace>/myhttp
Bind IP address, using
cf ic bind <IP> myhttp
Access your container with the IP you bound
I'm trying to run a simple Docker image with Apache and a PHP program. It works fine if I run
docker run -t -i -p 80:80 my/httpd /bin/bash
then manually start Apache
service httpd start
however I cant get httpd to start automatically when running
docker run -d -p 80:80 my/httpd
Apache will startup then container exists. I have tried a bunch of different CMDs in my docker file
CMD /etc/init.d/httpd start
CMD ["service" "httpd" "start"]
CMD ["/bin/bash", "/etc/init.d/httpd start"]
ENTRYPOINT /etc/init.d/httpd CMD start
CMD ./start.sh
start.sh is
#!/bin/bash
/etc/init.d/httpd start
However every-time docker instance will exist after apache starts
Am I missing something really obvious?
You need to run apache (httpd) directly - you should not use init.d script.
Two options:
you have to run apache in foreground: /usr/sbin/apache2 -DFOREGROUND ... (or /usr/sbin/httpd in CentOS)
you have to start all services (including apache configured as auto-run) by executing /sbin/init as entrypoint.
Add this line in the bottom of your Dockerfile to run Apache in the foreground on CentOS
ENTRYPOINT ["/usr/sbin/httpd", "-D", "FOREGROUND"]
Simple Dockerfile to run httpd on centOS
FROM centos:latest
RUN yum update -y
RUN yum install httpd -y
ENTRYPOINT ["/usr/sbin/httpd","-D","FOREGROUND"]
Commands for building images and running container
Build
docker build . -t chttpd:latest
Running container using new image
docker container run -d -p 8000:80 chttpd:latest
In the end of Dockerfile, insert below command to start httpd
# Start httpd
ENTRYPOINT ["/usr/sbin/httpd", "-D", "FOREGROUND"]
This works for me
ENTRYPOINT /usr/sbin/httpd -D start && /bin/bash