This Docker Project uses the latest versions of nginx and jenkins docker official images. You will be able to use nginx as a reverse proxy server to access jenkins automation server. This project is well-recommended for development purpose but if you want to work in production environment we tightly recommend you to work with the best lightweight alpine images, please review the alpine branch
- Install
Docker
andDocker Compose
. - At top level project run
docker-compose up
command from terminal. - Go to terminal and run:
docker ps
You will see two running containers as follows:
CONTAINER ID IMAGE ... PORTS NAMES
621282adb463 nginxproject_nginxservice ... 0.0.0.0:80->80/tcp nginxproject_nginxservice_1
4dd4d4c68b65 nginxproject_jenkinsservice ... 8080/tcp, 50000/tcp nginxproject_jenkinsservice_1
- Access to the running nginx container:
docker exec -i -t nginxproject_nginxservice_1 bash
- Inside the nginx docker container, we must create your own user basic auth
htpasswd /etc/apache2/.htpasswd 'YOUR_USER_NAME'
- You will be prompted to write a password.
- That's all, you have a nginx basic auth now.
Go to http://localhost/jenkins and you will be prompted to write you user authentication, write your YOUR_USER_NAME and PASSWORD as we explain above and could access to the jenkins server.
After enter your right credentials, you will be redirect to the jenkins server.
Keep in mind that jenkins container already has the jenkins user
. So you can clone any repository through this user. For that purpose, we are going to create our SSH keys inside the container:
- Enter to the jenkins repository:
docker exec -i -t nginxproject_jenkinsservice_1 bash
- Into the container, place into the JENKINS_HOME path (/var/jenkins_home) and try to clone your own repository with SSH, for instance:
git clone git@bitbucket.org:orbisunt/YOU_REPO.git
- You will be prompted like this:
The authenticity of host 'bitbucket.org (...)' can't be established.
RSA key fingerprint is SHA256:...
Are you sure you want to continue connecting (yes/no)?
-
Write
yes
and tap enter, the.ssh
folder will be created automatically and the bitbucket server host will be added into the known_hosts file (/var/jenkins_home/.ssh/known_hosts) -
Until this point, we can't clone our repository with SSH because we haven't created our SSH KEYS(private and public) yet. For that purpose, we need to run:
ssh-keygen
- Press enter and we'll have our private and public keys, something like this:
cd ~./ssh; ls
id_rsa id_rsa.pub known_hosts
- Go to Bitbucket -> bitbucket settings -> SSH Keys.
- Copy the content of your id_rsa.pub and add it.
- Once your bitbucket repository already has your public key, try to clone your repository with ssh again:
git clone git@bitbucket.org:orbisunt/YOU_REPO.git
- This time you will be able to clone your repository.
- Happy coding!!!!