What is i run docker run jenkins/jenkins? - jenkins

My question is like what if i run
docker run jenkins/jenkins
without specifying port details then will it run and if it run then on which port it will run? on default?

The Jenkins container will start and will be accessible within the Docker environment. (Container to Container communication) But you will not be able to access it via the Host machine. If you want to access the container from the host machine you have to bind the Jenkins port 8080 of the container to TCP port X of the host machine. You can use -p 8080:8080 option for this.

Related

Unable to access jenkins on port 8080 when running docker network host

I have a Jenkins running in a docker container in Linux ec2 instance. I am running testcontainers within it and I want to expose all ports to the host. For that I am using network host.
When I run the jenkins container with -p 8080:8080 everything works fine and I am able to access jenkins on {ec2-ip}:8080
docker run id -p 8080:8080 -p 50000:50000 jenkins/jenkins:lts
however, If I want to run the same image using --network=host as I want to expose all ports to the host
docker run id --network=host jenkins/jenkins:lts
{ec2-ip}:8080 becomes unreachable. I can curl to it locally within the container localhost:8080 but accessing jenkins from the browser doesn't work.
I am not sure how network host would change the way I access jenkins on port 8080. the application should be still available on port 8080 on the host IP address?
Check if you are enabling the port 8080 in the security group for the instance.
When a Docker container is running in the host network mode using the --network=host option, it shares the network stack with the Docker host. This means that the container is not isolated and uses the same network interface as the host.
In your case, you should be able to access the Jenkins from the browser with ec2-ip:8080
I tested it by running Jenkins with the following command:
docker run -id --name jenkins --network=host jenkins/jenkins:lts
if the issue still persists, you can check the following:
make sure the container is running
make sure that there is no other process is running on port 8080
make sure that you enabled the port 8080 for your ec2
AFAIU --network doesn't do what you expect it to do. --network flag allows you to connect the container to a network. For example, when you do --nerwork=host your container will be able to use the Docker host network stack. Not the other way around. Take a look at the official documentation.
Figured it out. needed to update iptables to allow port 8080 on network host.
sudo iptables -D INPUT -i eth0 -p tcp -m tcp --dport 8080 -m comment --comment "# jenkins #" -j ACCEPT

Docker container to network

I run docker container docker run -it --network host ubuntu:latest bash, but when I start there some server(on port 3000 for example), i can not open it from the main os.
How can I start the container (without describing expose or publish port) for up there some servers on different ports dynamicaly, and i want that ports will be available from the outer. I want to create container once, and keep there all changes, and back there via command docker start ..., docker exec ...
Visit this link to your solution
Here's Docker networking in the section The Host Driver
You will find the following abstract
As the name suggests, host drivers use the networking provided by the host machine. And it removes network isolation between the container and the host machine where Docker is running. For example, If you run a container that binds to port 80 and uses host networking, the container’s application is available on port 80 on the host’s IP address. You can use the host network if you don’t want to rely on Docker’s networking but instead rely on the host machine networking.
One limitation with the host driver is that it doesn’t work on Docker desktop: you need a Linux host to use it. This article focuses on Docker desktop, but I’ll show you the commands required to work with the Linux host.
The following command will start an Ubuntu image and listen to port 80 on the host machine:
docker run -it --network host ubuntu:latest /bin/bash

Google Cloud Run - how to specify docker command line arguments for GCR?

I have a Docker container that has a Flask server inside ran with Gunicorn.
Locally I run it using docker run -p 443:443 appcontainer and it works just fine.
I can't figure out how to tell Google Cloud Run to do the same, is it possible to specify the -p for it or any other Docker command line arguments for that matter?
According to the Docker documentation
Published ports
By default, when you create or run a container using docker create or
docker run, it does not publish any of its ports to the outside world.
To make a port available to services outside of Docker, or to Docker
containers which are not connected to the container’s network, use the
--publish or -p flag. This creates a firewall rule which maps a container port to a port on the Docker host to the outside world
Cloud Run (fully managed) always exposes services a single port (on :443) over HTTPS SO and cloud run container listen on default port 8080. From my understanding the default set up is something like (-p 443:8080).
However you can configure on which port requests are sent to the container if you want to change the default port 8080
Configuring the container port
gcloud run services update SERVICE --port 443

How to access a specific running host port from inside docker container

I am trying from within a Docker container to acces/share a port (7497) on the host that is already running. I am trying to "talk" to a program on the host that has a socket port running on 7497. This is setup on a unix host.
How can i expose only that specefic port for two way operation from docker when the port is alredy active on the host? Is it possible?
I cant map the port with example -p 7497:7497, as then i get an error "bind: address already in use". This error is correct as the port is used by the program in the host.
The only way i manage to get acces is to use --network host --userns=host in the run command when starting the container, example:
nvidia-docker run -e HOME=/tmp -it --rm -v /home/kc/Deep_Learning:/projects --network host --userns=host tf_py3_gpu_science:1.4
But this way i am exposing all ports, why i am worried for some safety issues.

How to access a port that is already used by another Docker container

I am running a Tomcat server on one Docker container. On another docker container, i want to be able to access that Tomcat server. So, what I do is to use the -p option to map that port to the port mapped by the Docker container running the Tomcat server.
In short, I have the Tomcat container, which was run using something like this.
docker run ... -p X:8080 ...
And the other docker container like this
docker run ... -p X:X ...
However, if I try to do so, I get "Port is already allocated" error. How can I solve this problem?
When you add -p X:Y you are mapping Y port from container to X port in host machine and making it accessable in host.
Lets assume your tomcat container is running on 8080:8080
Now you have another container running
You can access tomcat container inside 2nd container by internal IP.
If both containers are on default network.
Something like this 172.0.0.2:8080
You can get assigned internal IP for container by this
docker network inspect bridge
or
docker container inspect $id
where id is container id

Resources