Blits - blitterated/docker-dev-env GitHub Wiki

These don't really belong anywhere. They're mostly just temporary notes. Mostly.

They're called blits because I've moved a chunk of memory around.

Docker Cheatsheet

Quick test run commands

docker run -it --rm phusion/baseimage:focal-1.0.0 /sbin/my_init -- bash -l

docker run -it --rm --init debian bash
docker run -it --rm --init ubuntu bash

docker run -it --rm --init --mount type=bind,source="$(pwd)",target=/foo ubuntu bash

docker run -it --rm --init dde bash

Common dev commands

Build the image:

docker build -t dde .

Run the image:

docker run -it --rm --init dde /bin/bash

Remove the image:

docker rmi dde

Delete all <none> <none> images at once

newer way:

docker image prune

older way:

docker rmi $(docker images -qf "dangling=true")

Wipe out the build cache

docker builder prune -a

Flatten an image

The old export/import trick:

CONT_ID=$(docker create orig_image_name)
docker export $CONT_ID | docker import - lean_image_name
docker rm $CONT_ID

Run the flattened image:

docker run -it --rm lean_image_name /bin/bash

Attaching, detaching, and running detached commands

Good explanation of what -it means

Run a daemonized container and capture it's ID:

CONT_ID=$(docker run -itd --rm ubuntu /bin/bash)

Attach to the container:

docker attach $CONT_ID

Ctrl-d or typing exit at the console with shut the container down. Detach again with Ctrl-p Ctrl-q.

Execute a command on the container without attaching:

docker exec -d $CONT_ID touch /tmp/foo

Attach and verify the container is still running and that the command above ran:

docker attach $CONT_ID

root@7aaaec656f58:/# ls /tmp
foo

Clone the wiki

git clone git@ghblit:blitterated/docker_dev_env.wiki.git

List a package's dependencies with apt

Ask Ubuntu: How to list dependent packages (reverse dependencies)?

apt-cache rdepends --installed packagename

apt-cache rdepends --installed packagename | tail --lines=+3 | sort

apt list --installed

Notes from Zoom call with dev using Docker for dev env

  • JetBrains (RubyMine) works directly with Docker

  • Uses Docker Compose

    • Docker Compose exec session (tmux)
  • vim has a plugin for Docker

  • Uses tmux for multiple sessions in container.

  • hasn't used byobyu in a while

  • Using docker volumes faster than a bind mount when going from os x to linux fs.

    • NFS was faster than mounts, and he used it before using volumes

    • From an example docker-compose.yml

      foo: foo
        volumes:
          - .:/foo_app
          - gems:/gems
          # The below volumes are helpful to speed up docker on OSX
          # - node_modules:/foo_app/node_modules
          # - assets:/foo_app/public/assets
          # - test_data:/foo_app/public/test_data
          # - log:/foo_app/log
          # - tmp:/foo_app/tmp
          # - npmcache:/foo_app/.npmcache
      
      volumes:
        gems:
        # the following mounts can speed up docker on OSX
        # assets:
        # log:
        # node_modules:
        # npmcache:
        # test_data:
        # tmp:

JAremko's repositories, ideas, and software used

He does cool stuff with tmux, openrc, sshd, mosh, etc.

  • JAremko/alpine-vim
    • Look at user setup in Dockerfile
  • JAremko/drop-in
    • Look at setup of sshd in Dockerfile
      • ENTRYPOINT ["bash", "/usr/local/bin/start.bash"]
      • start.bash runs /usr/sbin/sshd -De
        • sshd manpage:
          • -D: sshd will not detach and does not become a daemon
          • -e: Write debug logs to standard error instead of the system log
    • It looks like it will run under OpenRC on quick glance, but a closer look shows that it's setup under OpenRC, started, and then stopped only during the image build. Why?
    • Look at mounting of ~/.ssh keys in example in README.md
    • Look at mounting of /etc/localtime for tmux in example in README.md
    • Has tmux, but doesn't appear to run it on container startup.
  • Mosh mobile shell

curl-ing the Docker API against the Docker socket

  • -X Specify HTTP request method
  • -d Sends the specified data in a POST request to the HTTP server

download latest nginx container

curl -XPOST --unix-socket /var/run/docker.sock "http://localhost/v1.41/images/create?fromImage=nginx:latest"

create a a container

RES_JSON=$(curl -XPOST --unix-socket /var/run/docker.sock -d '{"Image":"nginx"}' -H 'Content-Type: application/json' "http://localhost/containers/create")

extract new container's Id from JSON

CNT_ID=$(echo $RES_JSON | jq -r .Id)

run the container

curl -XPOST --unix-socket /var/run/docker.sock "http://localhost/containers/${CNT_ID}/start"

stop the container

curl -XPOST --unix-socket /var/run/docker.sock "http://localhost/containers/${CNT_ID}/stop"

rm the container

curl -XDELETE --unix-socket /var/run/docker.sock "http://localhost/containers/${CNT_ID}"

rmi the image

curl -XDELETE --unix-socket /var/run/docker.sock "http://localhost/images/nginx:latest"

Mistakes were made

I downloaded all the alpine images b/c there was no tag. Do NOT run this.

#curl -XPOST --unix-socket /var/run/docker.sock "http://localhost/v1.41/images/create?fromImage=alpine"

Deleted them all with this

docker rmi --force $(docker images -f "reference=alpine" -q)

Future investigations

⚠️ **GitHub.com Fallback** ⚠️