I added a firewall rule to open port 8080. If I click the SSH button in the GCE console, and run on the host shell:
nc -l -p 8080 127.0.0.1
I can detect the opened port. If I then go to the container's shell with:
docker run --rm -i -t <image> /bin/sh
and run the same netcat command, I can't detect the open port.
I went down this troubleshooting route because I couldn't connect to a node:alpine container running the ws npm for a demo websocket server. Here is my dockerfile:
# specify the node base image with your desired version node:<version>
FROM node:alpine
# replace this with your application's default port
EXPOSE 8080
WORKDIR /app
RUN apk --update add git
docker run --rm -i -t -p 8080:8080 <image> /bin/sh
per Google Compute Engine Container Port Closed
Related
I have this docker image that exposes port 5984 from a pouchdb-server running inside a docker container.
Here's what Dockerfile looks like:
From node:16-alpine
WORKDIR /pouchdb
RUN apk update
RUN npm install --location=global pouchdb-server
EXPOSE 5984
ENTRYPOINT ["pouchdb-server"]
CMD ["--port", "5984"]
Running the container using the default bridge network doesn't work:
docker run -d -v $(pwd)/pouchdb -p 5984:5984 pouchdb-server:v1
But upon running the container using the host docker network, it works like a charm.
docker run -d -v $(pwd)/pouchdb -p 5984:5984 --network host pouchdb-server:v1.
I understand that it removes the network isolation between docker and host network but this has the caveat of possible port conflicts.
My question is, is there any way to export make this work without using host network?
I am unable to run my docker image on Port 4000, even though I can run it on Port 80. What am I doing wrong here?
FROM node:latest as build
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
FROM nginx:latest
COPY --from=build /usr/src/app/dist/admin /usr/share/nginx/html
EXPOSE 4200
I'm creating the image using the following command:
docker build --pull --rm -f "DockerFile" -t admin1:v1 "."
When I run it on port 80, I'm able to use it:
docker run --rm -d -p 4200:4200/tcp -p 80:80/tcp admin1:v1
However, when I run the following command, I'm unable to use it:
docker run --rm -d -p 4200:4200/tcp -p 4000:4000/tcp admin1:v1
I have researched similar questions online, but I haven't been able to fix the problem. Any suggestion will be greatly appreciated!
You need to map the docker container port to the docker host port.
Try the following Command
docker run --rm -d -p 4200:4200/tcp -p 4000:80/tcp admin1:v1
The following is the extract from the Docker Documentation
-p 8080:80 Map TCP port 80 in the container to port 8080 on the Docker host.
You can refer the link for further information.
Docker Documentation
I would like to access the Star Wars Ascii movie from the telnet "towel.blinkenlights.nl" within a Docker Container.
Given this Dockerfile based on nerdalert:
FROM alpine:latest
RUN apk add busybox-extras
ENTRYPOINT ["/usr/bin/telnet", "towel.blinkenlights.nl"]
With this Docker Build & Run Commands:
docker build . -t starwars
docker run --rm -i -P starwars
I receive the following error messages:
telnet: can't connect to remote host (213.136.8.188): Connection refused
I also tried this Run Command with the same Error:
docker run --rm --network host -P starwars
and change the Dockerfile Baseimage to bitnami/minideb:stretch with no success.
How should I change the Dockerfile or the Docker run Command to access a (this) remote telnet server?
Without the Docker Container on my Windows Host system - I can access the telnet server towel.blinkenlights.nl easily
Using Ubuntu.
Based on this guide:
https://www.freecodecamp.org/news/how-to-use-routing-in-vue-js-to-create-a-better-user-experience-98d225bbcdd9/
I have created a minimal vuejs project with below project structure:
https://github.com/dev-samples/samples/tree/master/vuejs-001
frontend-router/
build/
config/
src/
static/
test/
build.sh
Dockerfile.dev
package-lock.json
package.json
Where:
Dockerfile.dev
FROM node:10
RUN apt install curl
RUN mkdir /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
# install and cache app dependencies
COPY package.json /app/package.json
# make the 'app' folder the current working directory before running npm install
WORKDIR /app
RUN npm install
CMD [ "npm", "run", "dev" ]
I am building the image and running the container from that image with:
docker build -t frontend-router-image -f Dockerfile.dev .
docker rm -f frontend-router-container
docker run -it -p 8081:8080 -v ${PWD}:/app/ -v /app/node_modules --name frontend-router-container frontend-router-image
which gives:
DONE Compiled successfully in 1738ms 3:49:45 PM
I Your application is running here: http://localhost:8080
Since I add -p 8081:8080 to docker run command I would expect that I can access the application from my host browser on:
http://localhost:8081/
but it just gives below error:
I works fine when I run it with vanilla npm from my host. But why can't I access the application when its run from inside a docker container?
Source code here:
https://github.com/dev-samples/samples/tree/master/vuejs-001
As suggested below I have tried:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e011fb9e39e8 frontend-router-image "docker-entrypoint.s…" 12 seconds ago Up 9 seconds 0.0.0.0:8081->8080/tcp frontend-router-container
$ docker run -it --rm --net container:frontend-router-container nicolaka/netshoot ss -lnt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.1:8080 0.0.0.0:*
For comparison this project works fine:
https://github.com/dev-samples/samples/tree/master/vuejs-002
Meaning that when I run a container I can access the web application on my host browser on localhost:8081
Based on this:
https://github.com/webpack/webpack-dev-server/issues/547
and:
https://dev.to/azawakh/don-t-forget-to-give-host-0-0-0-0-to-the-startup-option-of-webpack-dev-server-using-docker-1483
https://pythonspeed.com/articles/docker-connection-refused/
It works if I change:
host: 'localhost', // can be overwritten by process.env.HOST
to:
host: '0.0.0.0', // can be overwritten by process.env.HOST
in the file: /frontend-router/config/index.js
When you have connection reset it means usually that nobody is listen on the port .
It seems you are listening on localhost , you must
listening on 0.0.0.0 when you are in the docker .
in your file config/index.js , host is localhost , you must remove the host directive
If you listening on 127.0.0.1or localhost , you are listening on local network , so
inside the container , the web server can be accessed only by local process .
Another source of problems you can have , you are connecting to the wrong port .
if you run with docker run -it -p 8081:8080 you must acces to http://localhost:8081/
see
Publish or expose port (-p, --expose)
from https://docs.docker.com/engine/reference/commandline/run/
I just started using docker and followed following tutorial: https://docs.docker.com/engine/admin/using_supervisord/
FROM ubuntu:14.04
RUN apt-get update && apt-get upgrade
RUN apt-get install -y openssh-server apache2 supervisor
RUN mkdir -p /var/lock/apache2 /var/run/apache2 /var/run/sshd /var/log/supervisor
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
EXPOSE 22 80
CMD ["/usr/bin/supervisord"]
and
[supervisord]
nodaemon=true
[program:sshd]
command=/usr/sbin/sshd -D
[program:apache2]
command=/bin/bash -c "source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND"
Build and run:
sudo docker build -t <yourname>/supervisord .
sudo docker run -p 22 -p 80 -t -i <yourname>/supervisord
My question is, when docker runs on my server with IP http://88.xxx.x.xxx/, how can I access the apache localhost running inside the docker container from the browser on my computer? I would like to use a docker container as a web server.
You will have to use port forwarding to be able to access your docker container from the outside world.
From the Docker docs:
By default Docker containers can make connections to the outside world, but the outside world cannot connect to containers.
But if you want containers to accept incoming connections, you will need to provide special options when invoking docker run.
So, what does this mean? You will have to specify a port on your host machine (typically port 80) and forward all connections on that port to the docker container. Since you are running Apache in your docker container you probably want to forward the connection to port 80 on the docker container as well.
This is best done via the -p option for the docker run command.
sudo docker run -p 80:80 -t -i <yourname>/supervisord
The part of the command that says -p 80:80 means that you forward port 80 from the host to port 80 on the container.
When this is set up correctly you can use a browser to surf onto http://88.x.x.x and the connection will be forwarded to the container as intended.
The Docker docs describes the -p option thoroughly. There are a few ways of specifying the flag:
# Maps the provided host_port to the container_port but only
# binds to the specific external interface
-p IP:host_port:container_port
# Maps the provided host_port to the container_port for all
# external interfaces (all IP:s)
-p host_port:container_port
Edit: When this question was originally posted there was no official docker container for the Apache web server. Now, an existing version exists.
The simplest way to get Apache up and running is to use the official Docker container. You can start it by using the following command:
$ docker run -p 80:80 -dit --name my-app -v "$PWD":/usr/local/apache2/htdocs/ httpd:2.4
This way you simply mount a folder on your file system so that it is available in the docker container and your host port is forwarded to the container port as described above.
There is an official image for apache. The image documentation contains instructions in how you can use this official images as a base for a custom image.
To see how it's done take a peek at the Dockerfile used by the official image:
https://github.com/docker-library/httpd/blob/master/2.4/Dockerfile
Example
Ensure files are accessible to root
sudo chown -R root:root /path/to/html_files
Host these files using official docker image
docker run -d -p 80:80 --name apache -v /path/to/html_files:/usr/local/apache2/htdocs/ httpd:2.4
Files are accessible on port 80.