Skip to content
Bytes by Ying
Go back

#lifeprotip: Use Docker to simplify development workflows

Edit page

Overview

During my ongoing work on TinyDevCRM, I realized I need this ability to trace / audit / lock down dependencies while also not adversely impacting my development velocity during the MVP phase (where dependencies come and go in a game of musical chairs). I also want to reproducibly build and ship code when working through tutorials so that I can go back and reference them later. So I came up with this informal, hacky way to wrap all my “stuff” into one Docker container.

I’ve used it for a handful of projects I’ve worked on so far, and it’s honestly been great. I’ve shied away from sharing it until now due to how I might encourage bad habits for myself and others. After mulling it over though, I think if I found this workflow useful, it could prove useful to others in a similar situation. I also could put myself in a position where I could collect feedback and constructive criticism on how to improve this workflow.

End result

I published a basic GitHub repository here. I also added the minimal configuration below to get started. It’s really quite simple.

Directory structure:

$ tree .
.
├── Dockerfile
├── entrypoint.sh
└── run.sh

0 directories, 3 files

Dockerfile (chmod 644):

FROM ubuntu:18.04

ENTRYPOINT [ "/app/entrypoint.sh" ]

entrypoint.sh (chmod 755):

#!/usr/bin/env bash

tail -f /dev/null

run.sh (chmod 755):

#!/usr/bin/env bash

DOCKER=$(which docker)
GIT=$(which git)

GIT_REPO_ROOT=$(git rev-parse --show-toplevel)
DOCKER_IMAGE_NAME='dummy:latest'
DOCKER_CONTAINER_NAME='dummy'

$DOCKER build $GIT_REPO_ROOT/conf \
    --tag $DOCKER_IMAGE_NAME

CONTAINER_EXISTS=$($DOCKER ps -a --format '{{ .Names }}' --filter name=$DOCKER_CONTAINER_NAME)

if [ -n "$CONTAINER_EXISTS" ];
then
    $DOCKER stop $DOCKER_CONTAINER_NAME && $DOCKER rm $DOCKER_CONTAINER_NAME
fi

$DOCKER run \
    --name $DOCKER_CONTAINER_NAME \
    --network=host \
    --volume=$(pwd):/app \
    -itd $DOCKER_IMAGE_NAME

After executing cd /path/to/dir && ./run.sh && docker ps, you should see something like this:

$ ./run.sh && docker ps
Sending build context to Docker daemon  4.608kB
Step 1/2 : FROM ubuntu:18.04
 ---> 72300a873c2c
Step 2/2 : ENTRYPOINT [ "/app/entrypoint.sh" ]
 ---> Using cache
 ---> 23e7c598eb3e
Successfully built 23e7c598eb3e
Successfully tagged dummy:latest
dummy
dummy
f2b0480d5daf6f5cc9be33b38c5a4e37a70a96c4ab20db398f2c6561c982ad12
CONTAINER ID        IMAGE               COMMAND                CREATED                  STATUS                  PORTS               NAMES
f2b0480d5daf        dummy:latest        "/app/entrypoint.sh"   Less than a second ago   Up Less than a second                       dummy

Then you can execute docker exec -it dummy bash and “lift” yourself into the Docker context:

$ docker exec -it dummy bash
root@hostname:/#

Type exit to drop out of the Docker context:

root@hostname:/# exit
exit
$

I was going to describe the step-by-step process of how I arrived at this solution, but I felt maybe I can highlight the key points instead and let Docker’s documentation handle the rest:


Pros / cons

Pros

Cons


Hacker News

lobste.rs



Edit page
Share this post on:

Previous Post
DevOps is an Ice Rink
Next Post
Pioneering as a Process Person