diff --git a/docker-tutorial/README.md b/docker-tutorial/README.md new file mode 100644 index 0000000..facdab1 --- /dev/null +++ b/docker-tutorial/README.md @@ -0,0 +1,125 @@ +# How to use Docker and migrate your existing Apps to your Linux Server? +How to use Docker and migrate your existing Apps? We will cover all the cool advantages of containerization, and how to easily migrate and manage your existing services and apps into Docker Containers on your Linux Server! + +We will use the free and open-source software Docker. + + +Project Homepage: https://www.docker.com/ +Documentation: https://docs.docker.com/ + +Video: https://youtu.be/y0GGQ2F2tvs + +## Prerequisites + +- Linux Server running Ubuntu 20.04 LTS or newer + +*You can still install Docker on a Linux Server that is not running Ubuntu, however, this may require different commands!* + +## 1. Install Docker, and Docker-Compose + +You can still install Docker on a Linux Server that is not running Ubuntu, however, this may require different commands! + +### 1.1. Install Docker +```bash +sudo apt update + +sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common + +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - + +sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" + +sudo apt update + +sudo apt-get install docker-ce docker-ce-cli containerd.io +``` + +### 1.2. Check if Docker is installed correctly +```bash +sudo docker run hello-world +``` + +### 1.3. Install Docker-Compose + +Download the latest version (in this case it is 1.25.5, this may change whenever you read this tutorial!) + +```bash +sudo curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + +sudo chmod +x /usr/local/bin/docker-compose +``` + +### 1.4. Check if Docker-Compose is installed correctly +```bash +sudo docker-compose --version +``` + +### 1.5. (optional) Add your linux user to the `docker` group +```bash +sudo usermod -aG docker $USER +``` + +## 2. Docker Basics + +### 2.1. Run a Docker Container + +```bash +docker run hello-world +``` + +### 2.2. How to find Docker Images? + +To get new applications, just visit the [official Docker Hub](https://hub.docker.com/). Because most vendors and communities maintain their own images, you will find Images for many applications there. + +### 2.3. Expose Ports + +Run a simple NGINX webserver. + +```bash +docker run -p 80:80 -d nginx +``` + +### 2.4. Persistent Volumes + +```bash +docker run -p 80:80 -v nginx_data:/var/www/html -d nginx +``` + +### 2.5. Migrate static files to a Docker Volume + +Migrate a NGINX webserver to Docker. + +```bash +sudo systemctl stop nginx + +sudo systemctl disable nginx + +docker run -p 80:80 -v /var/www/html:/var/www/html -d nginx +``` + +### 2.6. Migrate databases to a Docker Volume + +Migrate a MySQL Server to Docker. + +```bash +sudo systemctl stop mysql-server + +sudo systemctl disable mysql-server + +docker run -v /var/lib/mysql:/var/lib/mysql -d mysql +``` + +## 3. Set up Portainer + +### 3.1. Create a new Docker Volume + +```bash +docker volume create portainer_data +``` + +### 3.2. Launch Portainer + +```bash +docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce +``` +