This guide walks you through the process of setting up two Docker containers using Dockerfiles, linking them with Docker Compose, and configuring Jenkins in a Docker swarm environment.
- Docker Desktop or Docker Daemon installed
Create the first Dockerfile with the required format and specifications. (Example given in the same folder)
Create the second Dockerfile with the required format and specifications. (Example given in the same folder)
Create a Docker Compose file that links Dockerfile 1 and Dockerfile 2. Ensure that the services are properly defined and can communicate with each other. (Example given in the same folder)
- Open your computer terminal.
- Open Docker Desktop. If you do not have Docker Desktop, start the Docker Daemon using the command:
dockerd
Navigate to the directory where Dockerfile 1 is located: cd /path/to/Dockerfile1
Build the Docker image for Dockerfile 1 using the command: docker build .
Navigate to the directory where Dockerfile 2 is located: cd /path/to/Dockerfile2
Build the Docker image for Dockerfile 2 using the command: docker build .
Navigate to the directory where the Docker Compose file is located: cd /path/to/docker-compose-file
Run the Docker Compose file to start the services: docker-compose -f <filename.yml> up
Ensure that both containers are up and running using the command: docker ps
Try to access it using the chosen local host IP, if it does not run, use the following command inside the container java -jar /usr/share/java/jenkins.war
The command to enter the container as a host is: docker exec -u 0 -it container-name bash
Finish installing the required plugins for Jenkins.
Run the Docker Daemon within the container: dockerd
Initialize Docker Swarm in the container, making it the managing node: docker swarm init this container will then become the managing node for the swarm, copy the given token in order to join the swarm in the other container.