Docker
Jump to navigation
Jump to search
1. Install docker from repos
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
2. Run the hello-world docker container
$ sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 0e03bdcc26d7: Pull complete Digest: sha256:31b9c7d48790f0d8c50ab433d9c3b7e17666d6993084c002c2ff1ca09b96391d Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash
3. Running the above yields this:
$ sudo docker run -it ubuntu bash Unable to find image 'ubuntu:latest' locally latest: Pulling from library/ubuntu 83ee3a23efb7: Pull complete db98fc6f11f0: Pull complete f611acd52c6c: Pull complete Digest: sha256:703218c0465075f4425e58fac086e09e1de5c340b12976ab9eb8ad26615c3715 Status: Downloaded newer image for ubuntu:latest root@86eecb5ba5a8:/#
You can see you're left with a root shell.
4. More ambitiously, let's try for a full mysql install in a container:
xxx@xxxbox:~$ sudo docker pull mysql/mysql-server:8.0 [sudo] password for xxx: 8.0: Pulling from mysql/mysql-server 501550cfd5c0: Pull complete e0509d775110: Pull complete d5a01765d011: Pull complete 970507e942eb: Pull complete Digest: sha256:0bb21c0f1aa9296e7deafacec5703b80e4d923dfdfcaa2efbe0c8377a8592128 Status: Downloaded newer image for mysql/mysql-server:8.0 docker.io/mysql/mysql-server:8.0
5. Check all your docker images:
$ sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu latest f63181f19b2f 9 days ago 72.9MB mysql/mysql-server 8.0 d320e74763f4 11 days ago 406MB hello-world latest bf756fb1ae65 13 months ago 13.3kB
6. Now that we have it, we can start it:
docker run --name=mysqli --restart on-failure -d mysql/mysql-server:8.0
This generates a 64-character string; its first 12 characters will form the CONTAINER ID you see when running docker ps
7. Check it's up and running:
$ sudo docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
b5f42f0a8336 mysql/mysql-server:8.0 "/entrypoint.sh mysq…" 30 seconds ago Up 29 seconds (health: starting) 3306/tcp, 33060-33061/tcp