Skip to content

Instantly share code, notes, and snippets.

@grayside
Last active February 15, 2018 21:12
Show Gist options
  • Save grayside/a2d1afaca0c1bb61eea0c9fb5dc16e14 to your computer and use it in GitHub Desktop.
Save grayside/a2d1afaca0c1bb61eea0c9fb5dc16e14 to your computer and use it in GitHub Desktop.
Outrigger/Docker Shenanigans Outside a Project Configuration
The individual files in this gist each have a unique trick to offer. They may be moved to official documentation or individual gists at a future date.
This file is mostly added because gists insist on titling the page with the alphabetically first file name, instead of the gist title.
# Suppose you'd like to quickly check what our PHP configuration provides. It's as simple as spinning up the raw container:
docker run --rm -it -l com.dnsdock.image=outrigger -l com.dnsdock.name=phpinfo outrigger/apache-php:php56 bash
# Navigate browser to http://phpinfo.outrigger.vm
# To see the PHPInfo() HTML in the BASH session, you may run 'curl localhost'

Deleting Things

For the docker ps command, the -a flag includes inactive containers and the -q flag suppress all output except for the container ID.

Remove All Inactive Containers

docker container prune

Remove All Exited Containers

docker ps -aq --filter "status=exited" | xargs docker rm -f

More on filtering: https://docs.docker.com/engine/reference/commandline/ps/#filtering

Remove All Created Containers

(Created = Created but not successfully started: https://stackoverflow.com/a/43734669/38408)

docker ps -aq --filter "status=created" | xargs docker rm -f

Remove All Containers for a Project

By container name prefix:

The equal operator wildcards by default. For an exact match, the value should be framed as ^/string$.

docker ps -aq --filter "name=^/projectname"

By outrigger.project label:

docker ps -aq --filter "label=outrigger.project=projectname" | xargs docker rm

Remove All Unused Images

docker image prune

Remove All Inactive Images with a Size in the GB

docker image ls | egrep "GB$" | awk '{ print $3 }' | xargs docker image rm -f
# Under high load, DNSDock will start to fail. For example, a migration/synchronization process facilitated by HTTP requests.
# If you don't want to hack your docker-compose.yml to add some hosts magic (https://docs.docker.com/compose/compose-file/#extra_hosts)
# You can directly edit the /etc/hosts file in a running container. It will only last until the container is stopped.
# If you do not want to look up the container name for a container managed in docker-compose with the service name `www`:
CONTAINER_NAME=$(fig ps -q www)
# If you have the container name handy:
CONTAINER_NAME=dynamic_duo_www
# Copy the IP address of the container you need to hardwire.
docker container inspect $CONTAINER_NAME --format="{{ .NetworkSettings.IPAddress }}" | pbcopy
# Start the container which needs the wiring. This works just as well as starting up a project build container.
docker run -it outrigger/build:php70 bash
# Edit the hosts file.
vi /etc/hosts
# Add a line. This requires manual interaction with the terminal. Yes, it could have been done fancier.
# <Cmd V> <www.image.vm>
# Now you do not need to rely on DNSDock for your domain configuration, and the container will resolve DNS without sending traffic out.
docker run -v ~/Downloads/drupal_target_db-20170725.sql:/dbs/latest.sql -e MYSQL_DATABASE=explore --name=projectname_explore_db --rm -d outrigger/mariadb:10.1
docker exec -it projectname_explore_db bash
mysql -uadmin -padmin explore < dbs/latest.sql
mysql -uadmin -padmin explore
docker run -it outrigger/build:php70 bash
# strace is one of a number of highly effective OS-level troubleshooting tools.
# You can use it inside your containers to look at system calls go by.
# It is not usable by default because it violates default security constraints.
# A] For `docker-compose`, modify build.yml:
# A1. Add these settings to base service definition to crack open almost all security constraints.
# + cap_add:
# + - SYS_PTRACE
# + security_opt:
# + - seccomp:unconfined
# A2. Start the container
docker-compose -f build.yml run --rm cli
# B] (Untested) For `docker run`, run with additional flags:
# B1. --cap-add=SYS_PTRACE --security-opt seccomp=unconfined
# B2. Run the container
docker run --rm -it --cap-add=SYS_PTRACE --security-opt seccomp=unconfined outrigger/build:php70 bash
# 3. Install strace in the container. It is not there by default.
yum install strace
# 4. Run strace
strace -p <pid> -s 100

Accessibility

Run against the selected URL. This is suitable for CI tools, as it will throw a non-zero exit code and can output to the console or via a reporting format (e.g., json, html)

docker run --rm -t jasonmce/pa11y www.phase2technology.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment