Dockerfile has no effect - docker

Am starting with Docker and running into an issue. I want to enabled mod_rewrite in an apache-container and am using this docker-compose.yml
version: '3'
services:
php-apache:
image: php:7.2.1-apache
ports:
- 80:80
volumes:
- ./DocumentRoot:/var/www/html:z
and this Dockerfile:
FROM php:7.2.1-apache
RUN a2enmod rewrite
RUN service apache2 restart
I run "docker build --no-cache ." with output:
Sending build context to Docker daemon 90.16MB
Step 1/3 : FROM php:7.2.1-apache
---> f99d319c7004
Step 2/3 : RUN a2enmod rewrite
---> Running in 883573f39a39
Enabling module rewrite.
To activate the new configuration, you need to run:
service apache2 restart
Removing intermediate container 883573f39a39
---> 18c40ce865a6
Step 3/3 : RUN service apache2 restart
---> Running in b79bab530dc7
Restarting Apache httpd web server: apache2AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
.
Removing intermediate container b79bab530dc7
---> 8e2cfa7094f7
Successfully built 8e2cfa7094f7
Result: mod_rewrite not installed. When I log in to the console and manually run "a2enmod rewrite" all works fine. What am I missing here?

The docker build --no-cache . creates the docker image <none>:<none>.
Your compose-file references the base image: php:7.2.1-apache. You're basically preparing an image that you're not using.
You might want to use the -t argument in order to tag the image that you are building and then reference that image in the compose file. E.g:
docker build -t my-awesome-php-with-a2enmod --no-cache .
version: '3'
services:
php-apache:
image: my-awesome-php-with-a2enmod
ports:
- 80:80
volumes:
- ./DocumentRoot:/var/www/html:z

Related

docker-compose error connection ECONNREFUSED

I have a web service that is packed inside Docker image. I use compose to build this image and run it. I use docker desktop to run docker containers.
So, to run service I just need to type:
docker-compose run app
compose file:
version: "3.6"
services:
app:
build:
context: .
target: app
ports
- 5001:5001
docker file:
FROM python:3.10-slim as app
RUN mkdir -p /app
WORKDIR /app
COPY entrypoint.sh .
CMD ["sh", "/app/entrypoint.sh"]
However, I face following issue: when I try to get this service GET http://localhost:5001/up I get Error: connect ECONNREFUSED
I can't figure out why I can't access service. Any help/comment/explanation will be mush appreciated.
Did you check if the docker is running using the command docker ps ?
If it's running, please check if the port is listening using netstat -tnulp | grep 5001
Also check if firewall is blocking the connection

docker-compose simple networking demo

I am new to docker and docker-compose and I'm trying to understand networking in docker. I have the following docker-compose.yml file
version: '3'
services:
app0:
build:
context: ./
dockerfile: Dockerfile0
app1:
build:
context: ./
dockerfile: Dockerfile1
And the Dockerfiles look like
FROM: python:latest
I'm using a python image because that's what I want for my actual use-case.
I run
docker-compose build
docker-compose up
output:
Building app0
Step 1/1 : FROM python:latest
---> 3624d01978a1
Successfully built 3624d01978a1
Successfully tagged docker_test_app0:latest
Building app1
Step 1/1 : FROM python:latest
---> 3624d01978a1
Successfully built 3624d01978a1
Successfully tagged docker_test_app1:latest
Starting docker_test_app0_1 ... done
Starting docker_test_app1_1 ... done
Attaching to docker_test_app0_1, docker_test_app1_1
docker_test_app0_1 exited with code 0
docker_test_app1_1 exited with code 0
From what I've read, docker-compose will create a default network and both containers will be attached to that network and should be able to communicate. I want to come up with a very simple demonstration of this, for example using ping like this:
docker-compose run app0 ping app1
output:
ping: app1: Name or service not known
Am I misunderstanding how docker-compose networking works? Should I be able to ping app1 from app0 and vice versa?
running on amazon linux.
docker-compose version version 1.23.2, build 1110ad01
You need to add something (a script, via CMD) to those Python containers that keeps them running, something listening on a port or a simple loop.
Right now they immediately terminate after starting and there is nothing to ping. (The whole container shuts down when its command finished)
Defining services in the docker-composer.yaml file maybe not not enough as if one service will be down the other one won't have information about it's IP address.
You can however create a dependence between them which will for example allow the instance to automatically start app1 service when you start app0.
Set following configuration:
version: '3'
services:
app0:
build:
context: ./
dockerfile: Dockerfile0
depends_on:
- "app1"
app1:
build:
context: ./
dockerfile: Dockerfile1
This is a good practice in case you want services to communicate between each other.

Docker BaseX DBA

I use the following docker compose file to start the basexhttp server and the dba:
version: '3'
services:
basexhttp:
image: basex/basexhttp
ports:
- "1984:1984"
- "8984:8984"
dba:
image: basex/dba:8.5.4
ports:
- "11984:1984"
- "18984:8984"
- "18985:8985"
According to the documentation I should get the dba page with:
http://<host>:18984/dba.
Returns No function found that matches the request.
How do I get this to work?
Hi bergtwvd — I am sorry but your example is slightly outdated, we no longer maintain a separate basex/dba image — mostly due to our DBA no longer supporting connecting to remote basex instances..
I think the best approach is building your own image based on our "official" basexhttp image, that contains the DBA code:
Download BaseX.zip from http://files.basex.org/releases/
Create an empty folder for building your docker image.
Create a Dockerfile inside that folder with the following contents:
# Dockerfile
FROM basex/basexhttp:9.1
MAINTAINER BaseX Team
ADD ./webapp /srv/basex/webapp
Copy the webpapp folder contained in basex.zip into the same folder your Dockerfile is in
Run docker build:
# docker build
docker build -t mydba .
Sending build context to Docker daemon 685.6kB
Step 1/3 : FROM basex/basexhttp:latest
---> c9efb2903a40
Step 2/3 : MAINTAINER BaseX Team
---> Using cache
---> 11228f6d7b17
Step 3/3 : COPY webapp /srv/basex/
---> Using cache
---> d209f033d6d9
Successfully built d209f033d6d9
Successfully tagged mydba:latest
You may as well use this technique with docker-compose:
#docker-compose.yml
version: '3'
services:
dba:
build:
context: .
dockerfile: Dockerfile
ports:
- "8984:8984"
You should now be able to open http://localhost:8984 and access the DBA.
Hope this helps.

Docker compose couldn't run static html pages

I have developed some static web-pages using jQuery & bootstrap.Here follows the folder structure,
Using below command i can able to run the docker image
Build the image
docker build -t weather-ui:1.0.0 .
Run the docker image
docker run -it -p 9080:80 weather-ui:1.0.0
Which is working fine and i can able to see the pages using http://docker-host:9080
But i would like to create a docker-compose for it,I have created a docker-compose file like below
version: '2'
services:
weather-ui:
build: .
image: weather-ui:1.0.0
volumes:
- .:/app
ports:
- "9080:9080"
The above compose file was not working and it stuck,
$docker-compose up
Building weather-ui
Step 1 : FROM nginx:1.11-alpine
---> bedece1f06cc
Step 2 : MAINTAINER ***
---> Using cache
---> ef75a70d43e8
Step 3 : COPY . /usr/share/nginx/html
---> 6fbc3a1d4aff
Removing intermediate container 2dc46f1f751d
Successfully built 6fbc3a1d4aff
WARNING: Image for service weather-ui was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Recreating weatherui_weather-ui_1 ...
Recreating weatherui_weather-ui_1 ... done
Attaching to weatherui_weather-ui_1
It stuck in the above line and i really don't know why it stuck?
Any pointers or hint would be great to resolve this issue.
As per Antonio edit,
I can see the running container,
$docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
69ea4ff1a3ea weather-ui:1.0.2 "nginx -g 'daemon ..." 6 seconds ago Up 5 seconds 80/tcp, 443/tcp, 0.0.0.0:9080->9080/tcp weatherui_weather-ui_1
But while launching the page i couldn't see anything.It says the site can't be reached
docker-compose up build your docker container (if not already done) and attach the container to your console.
If you open your browser, and go to http://localhost:9080, you should see your website.
You don't need to map a volume : volumes: - .:/app in docker-compose.yml because you already copy static files in Dockerfile :
COPY . /usr/share/nginx/html
If you want to launch your container in the background (or in "detached" mode), add -d option : docker-compose up -d.
And by default docker-compose to not "rebuild" container if already exists, to build new container each time, add --build option : docker-compose up -d --build.

Docker - issue command from one linked container to another

I'm trying to set up a primitive CI/CD pipeline using 2 Docker containers -- I'll call them jenkins and node-app. My aim is for the jenkins container to run a job upon commit to a GitHub repo (that's done). That job should run a deploy.sh script on the node-app container. Therefore, when a developer commits to GitHub, jenkins picks up the commit, then kicks off a job including automated tests (in the future) followed by a deployment on node-app.
The jenkins container is using the latest image (Dockerfile).
The node-app container's Dockerfile is:
FROM node:latest
EXPOSE 80
WORKDIR /usr/src/final-exercise
ADD . /usr/src/final-exercise
RUN apt-get update -y
RUN apt-get install -y nodejs npm
RUN cd /src/final-exercise; npm install
CMD ["node", "/usr/src/final-exercise/app.js"]
jenkins and node-app are linked using Docker Compose, and that docker-compose.yml file contains (updated, thanks to #alkis):
node-app:
container_name: node-app
build: .
ports:
- 80:80
links:
- jenkins
jenkins:
container_name: jenkins
image: jenkins
ports:
- 8080:8080
volumes:
- /home/ec2-user/final-exercise:/var/jenkins
The containers are built using docker-compose up -d and start as expected. docker ps yields (updated):
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
69e52b216d48 finalexercise_node-app "node /usr/src/final-" 3 hours ago Up 3 hours 0.0.0.0:80->80/tcp node-app
5f7e779e5fbd jenkins "/bin/tini -- /usr/lo" 3 hours ago Up 3 hours 0.0.0.0:8080->8080/tcp, 50000/tcp jenkins
I can ping jenkins from node-app and vice versa.
Is this even possible? If not, am I making an architectural mistake here?
Thank you very much in advance, I appreciate it!
EDIT:
I've stumbled upon nsenter and easily entering a container's shell using this and this. However, these both assume that the origin (in their case the host machine, in my case the jenkins container) has Docker installed in order to find the PID of the destination container. I can nsenter into node-app from the host, but still no luck from jenkins.
node-app:
build: .
ports:
- 80:80
links:
- finalexercise_jenkins_1
jenkins:
image: jenkins
ports:
- 8080:8080
volumes:
- /home/ec2-user/final-exercise:/var/jenkins
Try the above. You are linking by image name, but you must use container name.
In your case, since you don't specify explicitly the container name, it gets auto-generated like this
finalexercise : folder where your docker-compose.yml is located
node-app : container configs tag
1 : you only have one container with the prefix finalexercise_node-app. If you built a second one, then its name will be finalexercise_node-app_2
The setup of the yml files:
node-app:
build: .
container_name: my-node-app
ports:
- 80:80
links:
- my-jenkins
jenkins:
image: jenkins
container_name: my-jenkins
ports:
- 8080:8080
volumes:
- /home/ec2-user/final-exercise:/var/jenkins
Of course you can specify a container name for the node-app as well, so you can use something constant for the communication.
Update
In order to test, log to a bash terminal of the jenkins container
docker exec -it my-jenkins bash
Then try to ping my-node-app, or even telnet for the specific port.
ping my-node-app:80
Or you could
telnet my-node-app 80
Update
What you want to do is easily accomplished by the exec command.
From your host you can execute this (try it so you are sure it's working)
docker exec -i <container_name> ./deploy.sh
If the above works, then your problem delegates to executing the same command from a container. As it is you can't do that, since the container that's issuing the command (jenkins) doesn't have access to your host's docker installation (which not only recognises the command, but holds control of the container you need access to).
I haven't used either of them, but I know of two solutions
Use this official guide to gain access to your host's docker daemon and issue docker commands from your containers as if you were doing it from your host.
Mount the docker binary and socket into the container, so the container acts as if it is the host (every command will be executed by the docker daemon of your host, since it's shared).
This thread from SO gives some more insight about this issue.

Resources