Docker run port and permission issues

Hello All,

This is my first post on docker site ( in a fact first of my life :smiley: ) .
While running jenkins i encountered below error on my docker run command -

[jay@docker1 ~]$ docker run -p 8000:8000 -p 50000:50000 -v /jenkinsHome/jenkinsdata:/var/jenkins_home jenkins
touch: cannot touch β€˜/var/jenkins_home/copy_reference_file.log’: Permission denied
Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?

To resolve this, i checked the permissions on folder - /jenkinsHome/ and it was root. Since I was running command with user jay, I modified the permission of /jenkinsHome from root:root to jay:docker.

/**
[jay@docker1 ~] ls -ld /jenkinsHome drwxr-xr-x 3 jay jay 25 Jun 30 12:04 /jenkinsHome [jay@docker1 ~] id jay
uid=1000(jay) gid=1000(jay) groups=1000(jay),993(docker)
[jay@docker1 ~] sudo chown -R jay:docker /jenkinsHome [sudo] password for jay: [jay@docker1 ~]

[jay@docker1 ~]$ ls -ld /jenkinsHome
drwxr-xr-x 3 jay docker 25 Jun 30 12:04 /jenkinsHome

[jay@docker1 ~]$ docker run -p 8000:8000 -p 50000:50000 -v /jenkinsHome/jenkinsdata:/var/jenkins_home jenkins
Running from: /usr/share/jenkins/jenkins.war … << it started and success

**/

This issue got resolved.

Question is - If my logic was correct of changing the permissions from root to jay ?

Secondly, when my docker ran, at the end it stopped at -

INFO: Finished Download metadata. 9,554 ms
–> setting agent port for jnlp
–> setting agent port for jnlp… done

**All expected messages are shown but problem is - **
Site is not accessible with both hostname:8000 or ip-address:8000. Telnet also not works.
If I run with port 8080:8080 it’s a piece of cake. All runs smoothly.
So what am I missing here ?

Can I get help on these both topics ?

thanks in advance.
Jay

Further more testing, I came to know that when container port is kept to 8080 and host port is vary everything works fine.
So is it the case that jenkins always runs on 8080 port by default ?

I am newbie to both jenkins and docker.

thanks.

A port mapping is nothing then binding a port from the container to a port on your host. It has no effect on which port the actual service inside the container is running - how could it?!

The service inside a container usualy runs on its default port (which depends on the application of course!), unless the image creater decided to modify the application configuration to listen on a different port.

Some image authors add the functionality in their entrypoint script(s) to override configuration elements of the containerized application. If the Dockerhub description does not mention any ENV variable to change the default PORT, be sure the default port is used.

Why do you even care on which container port jenkins is running? Just change the host port in the mapping and you are good to go! The mapping -p 8000:8080 will make Jenkins accessible on β€˜http://localhost:8000’ (or replace localhost with your hostname or ip).

1 Like

Thanks Meyay !!

So what I understood is 1> image creator have configured the image to run on 8080 (container port) which I assigned to 8000 (host port) and it worked. 2> While downloading the image also check the instructions provided by the contributor.

Can you also check and let me know the issue I faced about permission and solution I applied ?

thanks in advance for it.

This Jenkins Dockerfile uses uid=1000 and gid=1000 by default. The entrypoint script does not support uid/gid mapping.

Either the owner of the mapped host folder needs to be 1000:1000 (on your host: chown -R 1000:1000 /jenkinsHome/jenkinsdata) OR you need to modify the folder permissions to permit the container user to write into the mapped folder (on your host: chmod 777 /jenkinsHome/jenkinsdata).