I'm working on a use case to create a Docker container for an apache server for a CMS application.
Below is the folder structure for the docket container.
apache-rproxy-docker (folder)
-docker-compose.yml
- httpd (folder)
- Dockerfile
- httpd.conf
docker-compose.yml
version: '2.1'
services:
apache:
build: httpd/
ports:
- "80:80"
networks:
- my_network
restart: always
networks:
my_network:
driver: bridge
Dockerfile
FROM httpd:2.4
COPY ./httpd.conf /usr/local/apache2/conf/httpd.conf
httpd.conf
Listen 80
ServerName localhost:80
ServerAdmin admin@localhost
ErrorLog logs/error.log
LogLevel error
###
# Note that the following LoadModule lines only represent the minimum 'Web-Developer' Suite configuration.
#
# Also note that some of the following LoadModule lines, which are commented out, are still loaded under…
# confSuite-extra*.conf
# confextra*.conf
# …configuration files -- for modular reasons.
#
# For example:
# mod_deflate is loaded under confSuite-extramod_deflate_logio.conf and NOT under httpd.conf
# status_module is loaded under confextrahttpd-info.conf and NOT under httpd.conf
#
# Check last part of httpd.conf for the Apache base and 'Web-Developer' *.conf files that are included.
###
#LoadModule actions_module modules/mod_actions.so
LoadModule alias_module modules/mod_alias.so
#LoadModule asis_module modules/mod_asis.so
#LoadModule auth_basic_module modules/mod_auth_basic.so
#LoadModule auth_digest_module modules/mod_auth_digest.so
#LoadModule authn_anon_module modules/mod_authn_anon.so
#LoadModule authn_dbm_module modules/mod_authn_dbm.so
#LoadModule authn_default_module modules/mod_authn_default.so
#LoadModule authn_file_module modules/mod_authn_file.so
#LoadModule authz_dbm_module modules/mod_authz_dbm.so
#LoadModule authz_default_module modules/mod_authz_default.so
#LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_host_module modules/mod_authz_host.so
#LoadModule authz_user_module modules/mod_authz_user.so
LoadModule autoindex_module modules/mod_autoindex.so
#LoadModule cern_meta_module modules/mod_cern_meta.so
#LoadModule cgi_module modules/mod_cgi.so
#LoadModule dav_module modules/mod_dav.so
#LoadModule dav_fs_module modules/mod_dav_fs.so
#LoadModule deflate_module modules/mod_deflate.so
LoadModule dir_module modules/mod_dir.so
#LoadModule env_module modules/mod_env.so
#LoadModule expires_module modules/mod_expires.so
#LoadModule file_cache_module modules/mod_file_cache.so
#LoadModule headers_module modules/mod_headers.so
#LoadModule imagemap_module modules/mod_imagemap.so
#LoadModule include_module modules/mod_include.so
#LoadModule info_module modules/mod_info.so
#LoadModule isapi_module modules/mod_isapi.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module modules/mod_mime.so
#LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule mpm_event_module modules/mod_mpm_event.so
#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
#LoadModule mpm_worker_module modules/mod_mpm_worker.so
LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
#LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
#LoadModule negotiation_module modules/mod_negotiation.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module modules/mod_setenvif.so
#LoadModule speling_module modules/mod_speling.so
#LoadModule status_module modules/mod_status.so
#LoadModule unique_id_module modules/mod_unique_id.so
#LoadModule userdir_module modules/mod_userdir.so
#LoadModule usertrack_module modules/mod_usertrack.so
#LoadModule vhost_alias_module modules/mod_vhost_alias.so
#CMS
<VirtualHost *:80>
ServerName cms.dev.local
ProxyPreserveHost On
#INCLUDE THE EXTRA PROXYPASS RULE FOR /site HERE
ProxyPass /site/ http://localhost:8080/site/
ProxyPass / http://localhost:8080/cms/
ProxyPassReverse / http://localhost:8080/cms/
ProxyPassReverseCookiePath /cms /
</VirtualHost>
I have a couple of issues which are holding me back,
Below is the output on executing docker inspect container_id.
[
{
"Id": "1d40fcc6c4c1383213386bbdfbed0434a4b86ebbfc79e18d450691d57f190c86",
"Created": "2018-11-19T21:32:39.9551494Z",
"Path": "httpd-foreground",
"Args": [],
"State": {
"Status": "exited",
"Running": false,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 0,
"ExitCode": 1,
"Error": "",
"StartedAt": "2018-11-19T21:32:40.7494723Z",
"FinishedAt": "2018-11-19T21:32:40.8537987Z"
},
"Image": "sha256:31f9d98b9ee458dbf1befb5e07c87c6ef959dcc2ef690fe523fd887b12f9dbf9",
"ResolvConfPath": "/var/lib/docker/containers/1d40fcc6c4c1383213386bbdfbed0434a4b86ebbfc79e18d450691d57f190c86/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/1d40fcc6c4c1383213386bbdfbed0434a4b86ebbfc79e18d450691d57f190c86/hostname",
"HostsPath": "/var/lib/docker/containers/1d40fcc6c4c1383213386bbdfbed0434a4b86ebbfc79e18d450691d57f190c86/hosts",
"LogPath": "/var/lib/docker/containers/1d40fcc6c4c1383213386bbdfbed0434a4b86ebbfc79e18d450691d57f190c86/1d40fcc6c4c1383213386bbdfbed0434a4b86ebbfc79e18d450691d57f190c86-json.log",
"Name": "/apache-rproxy-docker_apache2_1_71f4a0b7076b",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": [],
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "apache-rproxy-docker_spa_network",
"PortBindings": {
"80/tcp": [
{
"HostIp": "",
"HostPort": "80"
}
]
},
"RestartPolicy": {
"Name": "",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": [],
"CapAdd": null,
"CapDrop": null,
"Dns": null,
"DnsOptions": null,
"DnsSearch": null,
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "shareable",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": null,
"DeviceCgroupRules": null,
"DiskQuota": 0,
"KernelMemory": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": 0,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"MaskedPaths": [
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
],
"ReadonlyPaths": [
"/proc/asound",
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/4040cf05d15260b3de19e00df9ef8f05305e581372162d3d280603d1d741148a-init/diff:/var/lib/docker/overlay2/84adfc08eb41b4f6ede14df10775b291c8195ade8b5d6351892e7c0f0606bc92/diff:/var/lib/docker/overlay2/5e42bbf563f3fbc5829685509b13f1d5536886a68ee5bd913bd4910dc9737478/diff:/var/lib/docker/overlay2/48ccff5d0d55c955e8e3e49b62c01865826dbfd01bd25206c411ae69f08bda4e/diff:/var/lib/docker/overlay2/fa24d9a31cc583d8a9583e659d94a5fc507328449cfb066bbcd2d3da2d26d2bd/diff:/var/lib/docker/overlay2/33fec7b43c22926678461a9b352c8cafdc7ede8303cb3d90722e30c0f20731c2/diff:/var/lib/docker/overlay2/c91cbd2e7230cc22d9ac1e170ca724c478c4b708e0edc433dd035f4ff36d9957/diff",
"MergedDir": "/var/lib/docker/overlay2/4040cf05d15260b3de19e00df9ef8f05305e581372162d3d280603d1d741148a/merged",
"UpperDir": "/var/lib/docker/overlay2/4040cf05d15260b3de19e00df9ef8f05305e581372162d3d280603d1d741148a/diff",
"WorkDir": "/var/lib/docker/overlay2/4040cf05d15260b3de19e00df9ef8f05305e581372162d3d280603d1d741148a/work"
},
"Name": "overlay2"
},
"Mounts": [],
"Config": {
"Hostname": "1d40fcc6c4c1",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"80/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/apache2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"HTTPD_PREFIX=/usr/local/apache2",
"HTTPD_VERSION=2.4.37",
"HTTPD_SHA256=3498dc5c6772fac2eb7307dc7963122ffe243b5e806e0be4fb51974ff759d726",
"HTTPD_PATCHES=",
"APACHE_DIST_URLS=https://www.apache.org/dyn/closer.cgi?action=download&filename= \thttps://www-us.apache.org/dist/ \thttps://www.apache.org/dist/ \thttps://archive.apache.org/dist/"
],
"Cmd": [
"httpd-foreground"
],
"ArgsEscaped": true,
"Image": "apache-rproxy-docker_apache2",
"Volumes": null,
"WorkingDir": "/usr/local/apache2",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"com.docker.compose.config-hash": "df3b431078c66f67a39bb27012c1d8237e21a65cac4c1a69a30db3f25f27d7d3",
"com.docker.compose.container-number": "1",
"com.docker.compose.oneoff": "False",
"com.docker.compose.project": "apache-rproxy-docker",
"com.docker.compose.service": "apache2",
"com.docker.compose.slug": "71f4a0b7076baa5b84ae33dda673173f29bb709e4904493b2b80847fa98f8e4",
"com.docker.compose.version": "1.23.1"
}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "d27a9df7fe5a9e75f5c3444f95565389cccde58f3791237c266430b1cced8d18",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/d27a9df7fe5a",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"apache-rproxy-docker_spa_network": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"apache2",
"1d40fcc6c4c1"
],
"NetworkID": "c2a24a5495f429efcff44ca247af058e29503a8e5659355cab7d0f3fe135f3b8",
"EndpointID": "",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "",
"DriverOpts": null
}
}
}
}
]
I'm working on the docker for the first time. Any help would be really appreciated.
Thanks!
OK, I was able to reproduce your issue using the files you provided. It's weird that you're not getting more info in the logs. But here's how I debugged it:
The fact that the status is restarting
is bad - it means your container isn't staying up. I removed the restart: always
line, but got the same result.
Let's narrow down the problem some more. I built your Dockerfile and ran it by running the following commands in the httpd
directory: docker build -t apache-rproxy:latest . && docker run --rm -p 80:80 apache-rproxy:latest
. Unfortunately, I got the same error with no additional logs.
Let's debug some more. Try the same command with the official httpd image: docker run --rm -p 80:80 httpd:2.4
. Notice that this time, httpd starts and begins logging, and the container remains alive.
Now, the only difference between the httpd:2.4
image and the apache-rproxy:latest
image is your config file. So you something in your httpd.conf
is preventing apache from starting (or even logging anything). Work out what the problem is there and I think you'll have a working setup.