In this tutorial, we'll have a look at how to set up Docker on our freshly installed Ubuntu server. Docker is a great way to remove hardware dependency and isolate different services into containers. These containers can run on every system where Docker can be installed and can also be moved easily between systems. At the end of this tutorial, we will set up a small Java Minecraft server to show what we can achieve with Docker.
First we need to install the required packages for Docker:
sudo apt-get update sudo apt-get install ca-certificates curl gnupg lsb-release
Then we add the official Docker GPG keys:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Next we add the required repository information:
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Now we can finally install Docker:
sudo apt-get update sudo apt-get install docker-ce docker-ce-cli containerd.io
After executing all these commands, we verify that Docker has been installed successfully:
docker --version ## Docker version 20.10.8, build 3967b7d
The simplest way to use Docker is via
docker-compose. It allows defining files that contain all the information we need to run a Docker container.
First we download the
docker-compose bin file:
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Then we apply all the required permissions:
sudo chmod +x /usr/local/bin/docker-compose
Last but not least, we verify the successful installation:
docker-compose --version ## docker-compose version v2.0.0, build 1110ad01
As a little example, we will set up a small Minecraft server.
First we need to create the
docker-compose.yml file for our server:
sudo nano docker-compose.yml
We insert the following content:
version: '3.8' services: minecraft: image: itzg/minecraft-server container_name: Minecraft restart: unless-stopped ports: - 25565:25565/tcp volumes: - ./minecraft/:/data environment: - EULA=true - VERSION=LATEST - PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
This content sets the right image, ports, volumes, and environment variables.
Now we only need to start our server:
docker-compose up -d
The first run may take a while, as the Minecraft server has to be set up. After that is done, we can connect to our new Minecraft server.
To stop the server again, just use the following command:
That's it! Congratulations, you are now running a Minecraft server :tada:
More information about the Java Minecraft server image can be found here.
Docker makes it easy to get services up and running in minutes. You don't have to deal with hardware-specific configuration. Docker takes the hassle away from administrators and makes maintenance tasks easier. Also, different services can be split into different containers to keep them encapsulated in their own environment.
If you want to learn more about Docker, please visit the official website and read the docs.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
By making a contribution to this project, I certify that:
The contribution was created in whole or in part by me and I have the right to submit it under the license indicated in the file; or
The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same license (unless I am permitted to submit under a different license), as indicated in the file; or
The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it.
I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the license(s) involved.