Skip to content

Instantly share code, notes, and snippets.

@cinco
Forked from diegograssato/docker
Created August 15, 2018 05:18
Show Gist options
  • Select an option

  • Save cinco/20136383e7ae8eb36fd10e627734f4ce to your computer and use it in GitHub Desktop.

Select an option

Save cinco/20136383e7ae8eb36fd10e627734f4ce to your computer and use it in GitHub Desktop.
Docker
https://labs.play-with-docker.com/
docker container run --name c1 -ti alpine sh
docker ps
docker ps --all
docker container ls -a
docker image ls
docker container inspect c1
docker container rm c1
Creating new image
docker container run -ti ubuntu bash
apt-get update
apt-get install -y figlet
figlet "hello docker"
docker ps -a
docker container commit CONTAINER_ID
docker container diff <container ID>
That’s it - you have created your first image! Once it has been commited, we can see the newly created image in the list of available images.
docker image ls
docker image tag <IMAGE_ID> ourfiglet
docker image ls
docker container run ourfiglet figlet "Konica Minolta"
Dockerfile
index.js
var os = require("os");
var hostname = os.hostname();
console.log("hello from " + hostname);
FROM alpine
RUN apk update && apk add nodejs
COPY . /app
WORKDIR /app
CMD ["node","index.js"]
docker image build -t hello:v0.1 .
docker container run hello:v0.1
History
docker images
docker image history <image ID>
echo "console.log('this is v0.2');" >> index.js
docker image build -t hello:v0.2 .
docker container run hello:v0.2
FROM alpine
VOLUME ["/data"]
ENTRYPOINT ["/bin/sh"]
docker image build -t img1 .
docker images
docker container run --name c2 -ti img1
docker container stop c2 && docker container rm c2
Defining a volume and port
docker container run --name www -d -p 8080:80 -v $(pwd)/html:/usr/share/nginx/html nginx
ls /var/lib/docker/volumes/html/_data
docker container stop www && docker container rm www
docker container run --name www -d -p 8080:80 -v $(pwd)/html:/usr/share/nginx/html nginx
mkdir composetest
cd composetest
docker-compose -v
app.py
import time
import redis
from flask import Flask
app = Flask(__name__)
cache = redis.Redis(host='redis', port=6379)
def get_hit_count():
retries = 5
while True:
try:
return cache.incr('hits')
except redis.exceptions.ConnectionError as exc:
if retries == 0:
raise exc
retries -= 1
time.sleep(0.5)
@app.route('/')
def hello():
count = get_hit_count()
return 'Hello World! I have been seen {} times.\n'.format(count)
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True)
requirements.txt
flask
redis
Dockerfile
FROM python:3.4-alpine
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
CMD ["python", "app.py"]
docker-compose.yml
version: '3'
services:
web:
build: .
ports:
- "5000:5000"
redis:
image: "redis:alpine"
docker-compose build
docker images
docker-compose up
docker-compose ps
docker-compose up -d
docker-compose tail -f
docker-compose tail -f web
docker-compose tail -f redis
mkdir my_wordpress
cd my_wordpress/
docker-compose.yml
version: '3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
volumes:
db_data:
docker-compose up -d
docker-compose exec wordpress apt-get update
docker-compose exec wordpress apt-get install iputils-ping mysql-client
docker-compose exec wordpress bash
sytemctl - https://wiki.archlinux.org/index.php/Systemd_(Portugu%C3%AAs)
Systemd é um sistema e gerenciador de serviços para Linux, compatível com os scripts de inicializações SysV e LS. Systemd fornece recursos de paralelização agressivos, usa socket e ativação D-Bus para iniciar serviços, oferece o início de daemons on-demand,
systemctl list-units
systemctl --failed
systemctl list-unit-files
systemctl status
systemctl is-enabled
systemctl enable
systemctl disable unit
systemctl start unit
systemctl stop unit
systemctl restart unit
systemctl reload unit
journalctl -f
journalctl -u unit
lxc list
lxc exec first -- /bin/bash
lxc file pull first/etc/hosts .
lxc file push hosts first/tmp/
lxc stop first
lxc start first
SLide linux basic
- vim
- network
- filesystem
- etc
- usr
- tmp
- opt
- bin
- sbin
- find
- man
- pwd
- ls
- ps
- dir
- mkdir
- rm
- echo
- touch
-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment