Skip to content

Instantly share code, notes, and snippets.

@vvvhung
Last active July 29, 2018 08:39
Show Gist options
  • Save vvvhung/f980a773042c7af43820fcbffa2c1e3e to your computer and use it in GitHub Desktop.
Save vvvhung/f980a773042c7af43820fcbffa2c1e3e to your computer and use it in GitHub Desktop.
Docker

1. Save

https://docs.docker.com/engine/reference/commandline/save/#cherry-pick-particular-tags

$ docker commit <container ID> <image name>
$ login, pull, push

--- docker linux on window : require Hyper-V?

https://stefanscherer.github.io/run-linux-and-windows-containers-on-windows-10/

https://forums.aws.amazon.com/message.jspa?messageID=755831

http://www.deploycontainers.com/2017/10/25/uninstall-docker-windows-server-2016/

https://stackoverflow.com/questions/41709354/docker-ip-for-windows

Are you running "Docker for Windows" or "Docker Toolbox for Windows"? if it is Docker Toolbox, the default ip address should be 192.168.99.100, you should be able to see it when you start docker shell, otherwise the ip address should be same as your local machine.

-- docker deamon not run

https://forums.docker.com/t/restart-docker-service-from-command-line/27331/7

$ docker-machine restart

https://www.peterbe.com/plog/no-space-left-on-device-on-osx-docker

2. mornitor

-- view log

https://docs.docker.com/engine/reference/commandline/logs/#usage

--- vao docker (exec -i -t)

https://askubuntu.com/questions/505506/how-to-get-bash-or-ssh-into-a-running-container-in-background-mode

--kill process in docker

https://stackoverflow.com/questions/27757405/how-to-kill-process-inside-container-docker-top-command

-- custom port and ip

https://runnable.com/docker/binding-docker-ports

--copy from host to docker

https://stackoverflow.com/questions/22907231/copying-files-from-host-to-docker-container/31971697

-- gunicorn on docker

https://sebest.github.io/post/protips-using-gunicorn-inside-a-docker-image/

-- mount folder

https://rominirani.com/docker-on-windows-mounting-host-directories-d96f3f056a2c

-- environtment variable

https://stackoverflow.com/questions/33379393/docker-env-vs-run-export

-- print from docker

http://www.alecburton.co.uk/docker/containers/cups/dockerfile/linux/blog/hp/git/docker-compose/print/printing/2017/11/05/printing-from-a-docker-container.html

https://blog.onetwentyseven001.com/cups-raspberry-printer/#.W084Th6tTOR

-- clean cache

https://mohitgoyal.co/2017/07/03/clear-docker-cache-to-save-disk-space/

3. command

docker save --output /Users/louis/Documents/docker_flax.tar docker_flax

docker load --input docker_flax.tar

To rename (copy) an image, you give it a new tag, and then remove the old tag using the ‘rmi’ command:

$ docker tag <old_name> <new_name>
$ docker rmi <old_name>

This second step is scary, as ‘rmi’ means “remove image”. However, docker won’t actually remove the image if it has any other tags. That is, if you were to immediately follow this with: docker rmi <new_name>, then it would actually remove the image (assuming there are no other tags assigned to the image).

$ docker run -p 5000:5000 test_docker_flax

$ docker image ls
$ docker rmi <image ID> -f

$ docker build -t test_docker_flax .

$ docker container ls
$ docker stop <container ID>

$ docker stop $(docker ps -a -q)

$ docker images --filter dangling=true

$ docker rmi `docker images --filter dangling=true -q` -f

$ docker image tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]

$ docker login [OPTIONS] [SERVER]

$ docker run -p 5000:5000 -e WORKERS=2 -e CLASS=sync -e  TIMEOUT=120 -e KEEPALIVE=30 test_config_gunicorn

If you run out of disk space in your Docker containers on OSX, this is probably the best thing to run:

$ docker rm $(docker ps -q -f 'status=exited')

$ docker rmi $(docker images -q -f "dangling=true")

$ docker exec -i -t containerId /bin/bash

$ docker top <container ID>
$ kill -9 process_id

$ docker run -v d:/data:/data alpine ls /data
$ docker run -it -v d:/data:/data alpine /bin/sh

'run /bin/bash' after instantiating the container -> skip CMD

FROM ubuntu:16.04
RUN apt-get update
RUN apt-get install -y software-properties-common vim --no-install-recommends
RUN add-apt-repository ppa:jonathonf/python-3.6
RUN apt-get update
RUN apt-get install -y build-essential python3.6 python3.6-dev python3-pip python3.6-venv python3.6-tk
RUN apt-get install -y git
# update pip
RUN python3.6 -m pip install pip --upgrade
RUN python3.6 -m pip install wheel
RUN apt-get autoclean
RUN apt-get install -y locales
RUN locale-gen en_US.UTF-8
#RUN export LANG=en_US.UTF-8 LANGUAGE=en_US.en LC_ALL=en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US.en
ENV LC_ALL=en_US.UTF-8
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
# Install tesseract-ocr
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential apt-utils pkg-config\
cmake git libleptonica-dev libtesseract-dev libsm6 \
libgtk2.0-dev libgtk-3-dev python-tk \
tesseract-ocr tesseract-ocr-eng tesseract-ocr-osd tesseract-ocr-equ tesseract-ocr-jpn \
imagemagick libjpeg8 libpng12-0 libwebp5 libicu55 fontconfig-config libfontconfig1 \
libgif7 poppler-utils
RUN which tesseract | awk '{cmd="cp "$1" " $1"3";system(cmd)}'
RUN cd /app/setup/packages && dpkg -i *.deb
RUN which tesseract | awk '{cmd="cp "$1" " $1"4";system(cmd)}'
# Install any needed packages specified in requirements.txt
RUN cd /app/setup && python3.6 -m pip install --trusted-host pypi.python.org -r requirements.txt
RUN cd /app/setup && python3.6 -m pip install --trusted-host pypi.python.org -r server_api_requirements.txt
RUN cd /app/setup/packaging && python3.6 setup.py install --force
RUN cd /app/setup && cp fonts/* /usr/share/fonts/truetype/
# Make port 5000 available to the world outside this container
EXPOSE 5000
# Define environment variable
ENV NAME World
# Run app.py when the container launches
# CMD gunicorn server:app --workers=3 --bind=0.0.0.0:5000
CMD gunicorn server:app --config config.py --bind=0.0.0.0:5000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment