How To Run Docker Applications

How To Run Docker Applications

There are multiple ways to run Docker applications and the two that I use are “docker create” and “docker compose up”. Both have their pros and cons which I will explain in this post.

What is Docker Create?

Docker create command can be used to quickly fire up a Docker container. I use it mainly for testing Docker containers that are simple and without many dependencies. Docker Hub or the application’s Github page for example should outline the required variables that need to be set. If an application needs say mySQL and nginx it would make more sense to use docker compose.

When a container needs to have variables changed the container needs to be stopped and removed. Once that is completed the container can be re-created and started using the following commands:

docker stop <container-name>
docker rm <container-name>
docker create <container-name> <add rest of the required variables used when first deployed>
docker start <container-name>

When a container is to be updated the following commands can be executed:

docker pull <image-name>
docker stop <container-name>
docker rm <container-name>
docker create <container-name> <add rest of the required variables used when first deployed>

What is Docker Compose?

Docker compose is used to deploy multiple containers at a time which includes containers that can have multiple dependencies. Depending on my needs I sometimes jump straight to setting up a container in my docker compose file and deploying it. All that needs to be done is setup a “docker-compose.yml” file and define the containers inside of that file. A few important items to note are the syntax and formatting in the file matter which means that if something is misaligned or not in the proper format the Docker commands will throw an error. An easy way to check this is to run “docker-compose config” and it will indicate an error or will echo the contents of the file.

Some sample docker-compose commands:

Update all defined docker-compose images:
docker-compose pull
Deploy and/or deploy updated containers:
docker-compose up -d
Validate docker compose config file:
docker-compose config
Redeploy a select container:
docker-compose up -d --force-recreate --no-deps --build <container-name>

Example of Docker Create vs Docker Compose

Docker Create

docker pull hunterlong/statping
docker create --name=statping -e PUID=1000 -e PGID=1000 -p 8080:8080 -v C:/Docker/Statping:/app --restart unless-stopped hunterlong/statping
docker start statping

Docker Compose

version: '3.3'
        container_name: statping
            - PUID=1000
            - PGID=1000
            - '8080:8080'
            - 'C:/Docker/Statping:/app'
          - default
        restart: always
        image: hunterlong/statping