Can't access docker container in browser on redhat - docker

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.

Related

Tomcat Docker Image on EC2 instance: Public IP returns 404

I installed Tomcat Docker Image on Amazon EC2 Linux virtual machine by executing the following commands in the terminal:
docker pull tomcat
docker run --name tomcat-server -p 8080:8080 tomcat:latest
When I try to access tomcat instance by EC2 public IP:
http://35.171.195.176:8080/
The following response is returned:
HTTP Status 404 - Not Found
According to the followiing article:
https://www.topzenith.com/2020/07/http-status-404-not-found-docker-tomcat-image.html
Based on the docker community request, webapps folder has been moved
to the webapps.dist folder, which means webapps folder is empty and
there are no files to serve on the browser. That is why 404 was
returned.
To re-enable the webapps, you need to copy the files from webapps.dist to webapps. Here are the steps to run:
docker pull tomcat:latest
docker run -d --name mytomcat -p 8080:8080 tomcat:latest
docker exec -it mytomcat /bin/bash
cd webapps.dist/
cp -R * ../webapps
exit

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.

Is good idea to deploy production server using docker in ups?

I created a docker file that install my application for php and dependencies then use composer to install vendor packages all in docker container.
This container will link to MongoDB and Nginx to run.
It's ok for development but my question is it's ok to deploy my production env?
Consider in my production server I will install docker then run below command:
docker run --name MongoDB -d --rm mongodb:latest
docker run --name app --link MongoDb:mongodb -p 9000:9000 -d --rm myrepo/myapp:latest
docker run --link app:app --name Nginx --rm -d Nginx:latest
And then enter my domain.com and my production server using this dockers to run my app.
It's ok and stable?
You may want to use docker compose to setup the three as services and deploy the whole thing as one stack using docker-compose up
See this page for a sample

Apache website not updating after restarting 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?

Resources