Apache website not updating after restarting docker - docker

I have created an apache2 docker container
docker run -dit --name tecmint-web -p 8080:80 -v /home/user/website/:/usr/local/apache2/htdocs/ httpd:2.4
This is working. but if I stop this container and start again by docker restart <container-id>. It does not pick new html file from my /home/user/website/.
How can I realign these 2 directories after restarting docker?

Related

Mounting multiple directory's as an external volume - Docker

I am trying to run a Nginx Docker container with 3 directorys mounted as an external volume. When I mount just one the container is up and and running but when I mount 3 the container is created and then exits right away.
docker run -v ~/data/usr:/usr/share/nginx/ -v ~/data/etc:/etc/nginx/ -v ~/data/var:/var/log/nginx/ -d -p 80:80 --name webserver nginx
Any ideas?

why do i keep seeing nginx index.html on localhost when i run my docker image

I installed and run nginx on my linux machine to understand the configurations etc. After a while i decided to remove it safely by following this thread in order to use it in docker
By following this documentaion i run this command
sudo docker run --name ngix -d -p 8080:80 pillalexakis/myrestapi:01
And i saw ngix's homepage at localhost
Then i deleted all ngix images & stopped all containers and i also run this command
sudo docker system prune -a
But now restarted my service by this command
sudo docker run -p 192.168.2.9:7777:8085 phillalexakis/myfirstapi:01 and i keep seeing at localhost ngix index.html
How can i totally remove it ?
Note: I'm new with docker and i might have missed a lot of things. Let me know what extra docker commands should i run in order provide better information.
Assuming your host have been preparing as below
your files (index.html, js, etc) under folder - /myhost/nginx/html
your nginx configuration - /myhost/nginx/nginx.conf
Solution
map your files (call volume) on the fly from outside docker image via docker cli
This is the command
docker run -it --rm -d -p 8080:80 --name web \
-v /myhost/nginx/html:/usr/share/nginx/html \
-v /myhost/nginx/nginx.conf:/etc/nginx/nginx.conf \
nginx
copy your files into docker image by build your own docker image via Dockerfile
This is your Dockerfile under /myhost/nginx
FROM nginx:latest
COPY ./html/index.html /usr/share/nginx/html/index.html
This is the command to build your docker image
cd /myhost/nginx
docker build -t pillalexakis/nginx .
This is the command to run your docker image
docker run -it --rm -d -p 8080:80 --name web \
pillalexakis/nginx

Unable to run nginx inside docker

I am trying to run an nginx image inside a Docker container. I have tried these steps
ssh inside ubuntu docker image docker run -v /var/run/docker.sock:/var/run/docker.sock -it ubuntu:latest bash
Installed Docker
Run Nginx image docker run -d -p 80:80 nginx
curl localhost:80 gives Connection refused
Mapping docker.sock to containers means you will be using the docker daemon of the host machine, not the container's.
So when you run docker run -d -p 80:80 nginx command, the nginx container is created and run in host machine (sibling of the ubuntu container). Hence, 80:80 maps in the host machine.
Validate this by running docker ps in ubuntu container and in the host machine. The result should match. And I guess, you can do curl localhost in the host machine and hit the nginx server as well.

Can't access docker container in browser on redhat

I am trying to run docker container on Redhat. What I did as:
download nginx: docker pull nginx
created html file at home/username/index.html and wrote "Welcome. I am Nginx server locked inside Docker"
ran the command: docker run --name my-nginx-c2 -p 8080:80 -v /home/username/html/:/usr/share/nginx/html:ro -d nginx
ran: curl http://my-ip-address:8080 and can see the output "Welcome. I am Nginx server locked inside Docker"
now the problem is when I try to see it on browser that is http://my-ip-address:8080, it doesn't work.

How to start docker container process after restart machine?

If start a docker container like:
docker run -d -p 5000:5000 --name registry registry:2
It can be seen when run
docker ps
But after restart machine and run docker ps again, it can't been found.
When check docker ps -a can see it exist.
How to week it up at this case if don't want to kill this process to run a new one?
Docker containers don't start automatically on system boot because the Docker default restart policy is set to no.
To achieve that you shoud do:
docker update --restart=always <container ID or name>

Resources