Last active
October 1, 2017 06:23
-
-
Save alexandervantrijffel/dce04aa56e92494392e69dd554b7444f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# skip entry point and go directly to the shell with --entrypoint | |
docker run -it --rm --name goalpinebuild -v $(pwd)/../src:/in -v $(pwd)/../dockerleanalpineproduction:/out -v $(pwd):/work -e BUILDARGS="-ldflags \"-extldflags '-static'\" -o /out/ps-737migration-be" --entrypoint=/bin/sh goalpinebuild | |
# in docker run, ALWAYS PUT THE IMAGE NAME AT THE END, arguments after the image name are discarded! | |
sudo docker run --network=bridge -p 80:80 gowebapp | |
# update a single service in a docker compose composition | |
docker-compose up -d --no-deps --build <service_name> | |
# install docker-compose.yml as container with [dcsg](https://github.com/andreaskoch/dcsg/blob/develop/installer.go) | |
sudo dcsg install ./docker-compose.yml | |
sudo nano /etc/systemd/system/MYSERVICE.service # remove docker pull | |
sudo systemctl daemon-reload | |
sudo service MYSERVICE start | |
# allow the containers to connect to the host | |
# in host: | |
sudo sysctl -w net.ipv4.ip_forward=1 | |
# in docker-compose: | |
network_mode: bridge | |
extra_hosts: | |
- "thehost:172.17.0.1" | |
# setup postfix in docker host: | |
# add the docker0 network to mynetworks in /etc/postfix/main.cf | |
mynetworks = **172.17.0.0/24** 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 | |
# remove $mydomain and any other domains for which mail needs to be forwarded to the external relay server: | |
mydestination = $myhostname, $mydomain, example.com, localhost | |
# allow access to port 25 from the docker network: | |
sudo ufw allow from 172.17.0.0/24 to any port 25 | |
# add the docker host public fqdn to the SPF record | |
# after installation of postfix run | |
sudo cp /etc/resolv.cnf /var/spool/postfix/etc/ | |
sudo service postfix restart | |
# view pending / deferred mails: | |
postqueue -p | |
# retry mails | |
postqueue -f | |
# trap sigterm in docker run script: | |
# http://veithen.github.io/2014/11/16/sigterm-propagation.html | |
# save docker image as tar file: | |
docker save -o <save image to path> <image name> | |
# Transferring a Docker image via SSH, bzipping the content on the fly: | |
docker save <image> | bzip2 | pv | \ | |
ssh user@host 'bunzip2 | docker load' | |
# dump running or paused container (including changes not in the image) | |
docker export CONTAINER_ID > my_container.tar | |
# to do this in reverse (remote to local): | |
ssh target_server 'docker save image:latest | bzip2' | pv | bunzip2 | docker load | |
# load docker image: | |
docker load -i <path to image tar file> | |
# https://blog.giantswarm.io/moving-docker-container-images-around/ | |
# copy files between host and container: | |
docker cp foo.txt mycontainer:/foo.txt | |
docker cp mycontainer:/foo.txt foo.txt | |
mailserver startte niet op omdat /var/log niet gemapped was => oplossing: ./log met 777 mappen als volume voor /var/log | |
# show all containers | |
docker ps -a | |
docker ps --filter "status=exited" | |
# delete all containers | |
docker rm $(docker ps -a -q) | |
# delete all untagged images | |
docker rmi $(docker images | grep "^<none>" | awk "{print $3}") | |
docker rmi /roundcubemail | |
docker run --rm -P --name myfirstpostgres -e POSTGRES_PASSWORD=MYPASSWORD postgres | |
connect to postgres in docker (find port numer with docker ps) | |
psql -h localhost -p 32768 -d postgres -U postgres --password | |
docker network ls | |
docker network connect bridge mail | |
docker network inspect bridge | |
# koppel 2 docker-compose networks aan elkaar: | |
https://blog.virtualzone.de/2016/09/docker-compose-link-containers-outside-compose-file-using-external_links.html | |
# networking with compose | |
https://docs.docker.com/compose/networking/ | |
# build image | |
docker build -t myimagename . | |
# build compose | |
docker-compose up | |
docker-compose up -d # build and run as deamon | |
docker-compose stop | |
# run docker compose with interactive shell | |
docker-compose run --rm mail | |
execute bash on a running container | |
docker exec -ti mail /bin/bash | |
add account to postfix: | |
docker run --rm \ | |
-e MAIL_USER=MYUSER \ | |
-e MAIL_PASS=MYPASSWORD \ | |
-ti tvial/docker-mailserver:latest \ | |
/bin/sh -c 'echo "$MAIL_USER|$(doveadm pw -s SHA512-CRYPT -u $MAIL_USER -p $MAIL_PASS)"' >> config/postfix-accounts.cf | |
docker run --rm -P --name myfirstpostgres -e POSTGRES_PASSWORD=ZEPASSWORD postgres |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment