5.1. Docker Quick Start#

This lab will take you through the basic Docker workflow to supplement what I talked about in class. For today we’ll use a Dokuwiki container that’s prebuilt so that you can see how everything works. Next week we’ll build a container for our own application and do all of this again.

  1. Run DokuWiki in a container. Dokuwiki is a PHP based wiki site. You can find a Docker container for it on DockerHub that’s packaged by Bitnami. Bitnami makes a lot of conveniently packaged Docker containers. Start your

    $ docker run -it -p 8080:8080 bitnami/dokuwiki:latest

    The container will take a little while to start the first time because you have to download the image. Preview the application on localhost:8080 and you should see a fresh new Wiki! Just like your Django application you see the logs on your screen.

    Make a change to your Wiki and stop the docker command with a Ctrl-c.

  2. Inspect the container. Your container and all of its data were given a random name. Use docker ps to see it:

    $ docker ps -a
    CONTAINER ID   IMAGE                     COMMAND                  CREATED          STATUS         PORTS                              NAMES
    3f2f4283130b   bitnami/dokuwiki:latest   "/opt/bitnami/script…"   10 minutes ago   Up 2 minutes>8080/tcp, 8443/tcp   xenodochial_chatelet

    Make a note of the NAMES.

  3. Restart DokuWiki. The docker start command restarts a container that has been created and stopped. Do NOT use docker run to re-run a container. That will create new one:

    $ docker start xenodochial_chatelet

    Make sure it’s running:

    $ docker ps 
    CONTAINER ID   IMAGE                     COMMAND                  CREATED          STATUS          PORTS                              NAMES
    3f2f4283130b   bitnami/dokuwiki:latest   "/opt/bitnami/script…"   18 minutes ago   Up 10 minutes>8080/tcp, 8443/tcp   xenodochial_chatelet
  4. Check the container logs. The restarted container is no longer in the foreground, so we don’t see it’s output. But, Docker is keeping track of the output. We can see it with the docker logs command:

    $ docker logs xenodochial_chatelet
  5. Get a shell in your container. What if you want to login to your container and look around? It’s easy. Just create a new interactive shell by running the /bin/bash command:

    $ docker exec -it xenodochial_chatelet /bin/bash
    I have no name!@3f2f4283130b:/$ 

    Notice how the prompt changed! Look around inside your container for a while. Exit the container with the exit command.

  6. Stop the container.* You can stop the container running in the background with:

    $ docker stop xenodochial_chatelet
  7. Remove the container. Remove your stopped container:

    $ docker rm xenodochial_chatelet

    Notice no more container:

    $ docker ps -a

Once you have these essential Docker commands memorized, it’s easy to see how you can create and manage web applications.