On my host machine, I have installed docker. Then I pull a Jenkins image.
I want to run that image like daemon service like some services runs on my host machine after rebooting my machine every time. And how can I fix Jenkins port permanent(like 8080) in mine docker?
docker run -d --restart always -p 8080:8080 -p 50000:50000 -v /your/home:/var/jenkins_home jenkins
-d: for running the container in background
--restart always: for the container to always restart (unless manually stopped), it will start automatically at boot.
The rest of the arguments are from the jenkins image documentation, you may need to adapt your port mapping and volume path.
Related
On my Redhat7linux docker host, i have created a jenkins container by pulling the jenkins official image from docker hub and i was able to bring the jenkins container up & running by executing the command:
docker run -d -p 50000:8080 -v $PWD/jenkins:/var/lib/jenkins -t jenkins_master
and i could see the jenkins is up when i checked the logs using the docker logs {containerID} but when i try to launch it in web browser with {hostip}:50000, I couldn't access it as it throws "The site cant be reached", and since my container is running inside a company network, should I either open/enable that port 50000 or do I need to set any proxy in the docker host?
Am I missing something here?
Here are the outputs of the docker command:
The official image provide the following command :
docker run -p 8080:8080 -p 50000:50000 -v /your/home:/var/jenkins_home jenkins
It seems that both ports 8080 and 50000 have to be exposed.
Execute the docker run command to run the container, check the status of your container.
docker container run -p [YOUR PORT]:8080 -v [YOUR
VOLUME]:/var/jenkins_home
--name jenkins-local jenkins/jenkins:lts
you can then access it using localhost:[YOUR PORT]
So on my server, I run my docker container as a daemon process via:
docker run -p 80:80 -td example
It seems to work fine - for now!
But, what if I restart my server or my docker container crashes? Then it doesn't work fine.
What is the best/conventional/standard way to keep my docker container running?
Thanks!
What you are looking for is an orchestrator. An orchestrator will manage your container life cycle for you. You might want to try the Docker orchestrator, Swarm. You can also check Kubernetes or Mesos.
You could also use Docker compose to make things easier.
As #wassim-dif pointed out you might want to use an orchestrator.
If you just want your docker container to restart automatically in case of failure and when you restart your server then you need to run it using the --restart flag, such as:
docker run -p 80:80 -td --restart=always example
This way, your container will restart automatically.
Our jenkins deploys/builds code in a docker container. Every time Jenkins deploys code, it does so in different instance of docker container. How do I know IP address of that container along with port id? Immediately after deployment I want to run my Build Validation test against the application residing in that docker container.
Any insight would be appreciated.
You need to specify -p in docker run and then use docker inspect to grab the port:
docker run -d -p 80 --name app crramirez/limesurvey
export THEPORT=`docker inspect --format='{{(index (index .NetworkSettings.Ports "80/tcp") 0).HostPort}}' app`
Then you call your application: wget http://localhost:${THEPORT}
All of this is necessary if you have many containers running concurrently. But if you only deploy one container at time. You only need to delete the previous container and do a docker run -d -p 80:80 call your application using your port wget http://localhost:80
Regards
I have found a similar thread, but failed to get it to work. So, the use case is
I start a container on my Linux host
docker run -i -t --privileged -p 8080:2375 mattgruter/doubledocker
When in that container, I want to start another one with GAE SDK devserver running.
At that, I need to access a running app from the host system browser.
When I start a container in the container as
docker run -i -t -p 2375:8080 image/name
I get an error saying that 2375 port is in use. I start the app, and can curl 0.0.0.0:8080 when inside both containers (when using another port 8080:8080 for example) but cannot preview the app from the host system, since lohalhost:8080 listens to 2375 port in the first container, and that port cannot be used when launching the second container.
I'm able to do that using the image jpetazzo/dind. The test I have done and worked (as an example):
From my host machine I run the container with docker installed:
docker run --privileged -t -i --rm -e LOG=file -p 18080:8080
jpetazzo/dind
Then inside the container I've pulled nginx image and run it with
docker run -d -p 8080:80 nginx
And from the host environment I can browse the nginx welcome page with http://localhost:18080
With the image you were using (mattgruter/doubledocker) I have some problem running it (something related to log attach).
We can create a new container and define your application port in docker run command like
sudo docker run -d -p 5000:5000 training/webapp python app.py
or
sudo docker run -d -P training/webapp python app.py
But, what if someone forgot to specify -p or -P option in docker run command? The container get created and runs the application locally. Now how could I assign a port on which application is running locally in container to the port of my Ubuntu host machine?
Kindly, help on this.
Thanks.
Short: You can't. You need to stop the container (or not) and start a new one with the proper parameters.
Docker spins up a local proxy and setup the iptables for proper NAT. If you really can't start a new container, you could manually setup the iptables and spin up a socat. You can take a look at the network part of the Docker code for more info.