One of the sessions at JaxLondon, Paul Stack mentioned they were running TeamCity on containers at HashiCorp. Because I am doing quite a number of trainings, demos, talks about Continuous Delivery, having the CI server/agents portable and containerised is a big win for me. After I saw JetBrains has the official docker image [for the server and the agents] at DockerHub, I decided to do it sooner, than later.
There are quite things I will cover to have a good touch on containers.
I will use docker’s Mac Toolbox to create TeamCity server and agents. There will be 2 folders required on my host for TeamCity server: data folder, and logs folder to be introduced as volumes to the server container.
Step2: Creating VirtualBox VMs:
I have my Mac Toolbox installed on Mac. Why not Docker-for-Mac, purely I want to rely on VirtualBox to manage my machines, and keep environment variables for Virtualbox VMs.
mymac:~ demokritos$ docker-machine create --driver virtualbox teamcityserver mymac:~ demokritos$ docker-machine start teamcityserver Starting "teamcityserver"... (teamcityserver) Waiting for an IP... Machine "teamcityserver" was started. Waiting for SSH to be available... Detecting the provisioner... Started machines may have new IP addresses. You may need to re-run the `docker-machine env` command. mymac:~ demokritos$ docker-machine env teamcityserver export DOCKER_TLS_VERIFY="1" export DOCKER_HOST="tcp://192.168.99.100:2376" export DOCKER_CERT_PATH="/Users/demokritos/.docker/machine/machines/teamcityserver" export DOCKER_MACHINE_NAME="teamcityserver" # Run this command to configure your shell: # eval $(docker-machine env teamcityserver) mymac:~ demokritos$ eval $(docker-machine env teamcityserver)
Step2: Create and share our volumes:
We need to create folders, give permission to our group [my user is in wheel group], and share folder with docker. You can see `stat $folder` to display the permissions.
mymac:~ demokritos$ sudo mkdir -p /opt/teamcity_server/logs mymac:~ demokritos$ sudo mkdir -p /data/teamcity_server/datadir mymac:~ demokritos$ sudo chmod g+rw /opt/teamcity_server/logs mymac:~ demokritos$ sudo chmod g+rw /data/teamcity_server/datadir
And share on Docker preferences
This will avoid errors like :
docker: Error response from daemon: error while creating mount source path ‘/opt/teamcity_server/logs’: mkdir /opt/teamcity_server/logs: permission denied.
Step3: Run the docker:
sudo docker run -it --name teamcityserver \ -e TEAMCITY_SERVER_MEM_OPTS="-Xmx2g -XX:MaxPermSize=270m \ -XX:ReservedCodeCacheSize=350m" -v /data/teamcity_server/datadir:/data/teamcity_server/datadir \ -v /opt/teamcity_server/logs:/opt/teamcity_server/logs \ -p 50004:8111 jetbrains/teamcity-server
If you get an error like :
docker: Error response from daemon: Conflict. The container name "/teamcityserver" is already in use by container 4143c2d13192b8020f066b13a2c033750b4ac1ac7d54e822a6b31a5f47489647. You have to remove (or rename) that container to be able to reuse that name..
Then, if you can find them with “ps -aq”, you can remove them in your terminal, if not open a new one and remove it, i.e:
docker rm 4143c2d13192
There is a long discussion on moby’s github site, if you are interested in …
And TC server is ready to be configured… Next, we will set up the agents…