Difference between revisions of "Docker"
Jump to navigation
Jump to search
Rafahsolis (talk | contribs) m Tag: visualeditor-switched |
Rafahsolis (talk | contribs) Tag: visualeditor |
||
| Line 22: | Line 22: | ||
==Docker Swarm== | ==Docker Swarm== | ||
| − | + | <source lang="bash">docker swarm init --advertise-addr=<IP-ADDRESS-OF-MANAGER> | |
docker network create -d overlay nginx-proxy | docker network create -d overlay nginx-proxy | ||
docker pull postgres:10.6 && docker pull redis:3.2-alpine && docker pull jwilder/nginx-proxy</source> | docker pull postgres:10.6 && docker pull redis:3.2-alpine && docker pull jwilder/nginx-proxy</source> | ||
==Examples== | ==Examples== | ||
| − | <source lang=bash>docker pull python:2.7 | + | <source lang="bash">docker pull python:2.7 |
docker run -i -t python:2.7 | docker run -i -t python:2.7 | ||
docker docker run -i -t python:2.7 bash | docker docker run -i -t python:2.7 bash | ||
| Line 48: | Line 48: | ||
=Restart stopped container with diferent command= | =Restart stopped container with diferent command= | ||
Find your stopped container id | Find your stopped container id | ||
| − | <source lang=bash>docker ps -a</source> | + | <source lang="bash">docker ps -a</source> |
Commit the stopped container: | Commit the stopped container: | ||
This command saves modified container state into a new image user/test_image | This command saves modified container state into a new image user/test_image | ||
| − | <source lang=bash>docker commit $CONTAINER_ID user/test_image</source> | + | <source lang="bash">docker commit $CONTAINER_ID user/test_image</source> |
Start/run with a different entry point: | Start/run with a different entry point: | ||
| − | <source lang=bash>docker run -ti --entrypoint=sh user/test_image</source> | + | <source lang="bash">docker run -ti --entrypoint=sh user/test_image</source> |
==Restart exited container== | ==Restart exited container== | ||
| − | <source lang=bash>docker start `docker ps -q -l` # restart it in the background | + | <source lang="bash">docker start `docker ps -q -l` # restart it in the background |
docker attach `docker ps -q -l` # reattach the terminal & stdin</source> | docker attach `docker ps -q -l` # reattach the terminal & stdin</source> | ||
==Create & Publish image== | ==Create & Publish image== | ||
| − | <source lang=bash>mkdir rpi_python | + | <nowiki><source lang=bash>mkdir rpi_python</nowiki> |
| − | nano rpi_python/Dockerfile<source | + | nano rpi_python/Dockerfile<nowiki></source></nowiki> |
Docekerfile | Docekerfile | ||
<nowiki># Pull base image | <nowiki># Pull base image | ||
| − | + | FROM resin/rpi-raspbian:wheezy | |
| − | + | MAINTAINER Dieter Reuter <dieter@hypriot.com> | |
| − | + | ||
| − | + | # Install dependencies | |
| − | + | RUN apt-get update && apt-get install -y \ | |
| − | + | python \ | |
| − | + | python-dev \ | |
| − | + | python-pip \ | |
| − | + | python-virtualenv \ | |
| − | + | --no-install-recommends && \ | |
| − | + | rm -rf /var/lib/apt/lists/* | |
| − | + | ||
| − | + | # Define working directory | |
| − | + | WORKDIR /data | |
| − | + | ||
| − | + | # Define default command | |
| − | + | CMD ["bash"]</nowiki> | |
docker build -t DOCKER_HUB_USERNAME/rpi_python:0.0.1 . | docker build -t DOCKER_HUB_USERNAME/rpi_python:0.0.1 . | ||
| Line 97: | Line 97: | ||
<nowiki>210 | <nowiki>210 | ||
| − | + | down vote | |
| − | + | accepted | |
| − | + | ||
| − | + | ||
| − | + | You need to commit the changes you make to the container and then run it. Try this: | |
| − | + | ||
| − | + | sudo docker pull ubuntu | |
| − | + | ||
| − | + | sudo docker run ubuntu apt-get install -y ping | |
| − | + | ||
| − | + | Then get the container id using this command: | |
| − | + | ||
| − | + | sudo docker ps -l | |
| − | + | ||
| − | + | Commit changes to the container: | |
| − | + | ||
| − | + | sudo docker commit <container_id> iman/ping | |
| − | + | ||
| − | + | Then run the container: | |
| − | + | ||
| − | + | sudo docker run iman/ping ping www.google.com</nowiki> | |
| − | == Docker mirror == | + | ==Docker mirror== |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
#!/bin/bash | #!/bin/bash | ||
Revision as of 14:40, 25 March 2019
Install
sudo apt-get remove docker docker-engine docker.io
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
apt-get update
# At production usse specific version:
apt-cache madison docker-ce
apt-get install docker-ce=18.03.0~ce-0~ubuntu
# Otherwise apt install docker-ce
sudo curl -L https://github.com/docker/compose/releases/download/1.20.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
sudo curl -L https://raw.githubusercontent.com/docker/compose/1.20.1/contrib/completion/bash/docker-compose -o /etc/bash_completion.d/docker-compose
### old: curl -sSL https://get.docker.com/ | sh
Docker Swarm
docker swarm init --advertise-addr=<IP-ADDRESS-OF-MANAGER>
docker network create -d overlay nginx-proxy
docker pull postgres:10.6 && docker pull redis:3.2-alpine && docker pull jwilder/nginx-proxy
Examples
docker pull python:2.7
docker run -i -t python:2.7
docker docker run -i -t python:2.7 bash
docker ps -a
docker pull linuxkonsult/kali-metasploit
docker search kali
docker run -ti -v "/home/rafa/LocalPath:/ContainerPath" git.rra.lan:4443/docker/pilaf_testrunner/converter:latest /bin/bash # mounts local path folder on docker container
docker images
docker run -i -t linuxkonsult/kali-metasploit bash
# Remove all containers
docker rm $(docker ps -aq)
# Remove one image
docker rmi ae024c7584a3
# Remove incompletely built images:
docker images | grep -v IMAGE\ ID | awk '{print "docker rmi " $3;}'
Restart stopped container with diferent command
Find your stopped container id
docker ps -a
Commit the stopped container: This command saves modified container state into a new image user/test_image
docker commit $CONTAINER_ID user/test_image
Start/run with a different entry point:
docker run -ti --entrypoint=sh user/test_image
Restart exited container
docker start `docker ps -q -l` # restart it in the background
docker attach `docker ps -q -l` # reattach the terminal & stdin
Create & Publish image
<source lang=bash>mkdir rpi_python nano rpi_python/Dockerfile</source>
Docekerfile
# Pull base image
FROM resin/rpi-raspbian:wheezy
MAINTAINER Dieter Reuter <dieter@hypriot.com>
# Install dependencies
RUN apt-get update && apt-get install -y \
python \
python-dev \
python-pip \
python-virtualenv \
--no-install-recommends && \
rm -rf /var/lib/apt/lists/*
# Define working directory
WORKDIR /data
# Define default command
CMD ["bash"]
docker build -t DOCKER_HUB_USERNAME/rpi_python:0.0.1 . # Or with multiple tags docker build -t DOCKER_HUB_USERNAME/rpi_python:0.0.1 -t DOCKER_HUB_USERNAME/rpi_python:latest . # List images docker images # Test image docker run -rm -it DOCKER_HUB_USERNAME/rpi_python:0.0.1 # Login docker login docker push DOCKER_HUB_USERNAME/rpi_python:0.0.1
Pull Modify Commit
210 down vote accepted You need to commit the changes you make to the container and then run it. Try this: sudo docker pull ubuntu sudo docker run ubuntu apt-get install -y ping Then get the container id using this command: sudo docker ps -l Commit changes to the container: sudo docker commit <container_id> iman/ping Then run the container: sudo docker run iman/ping ping www.google.com
Docker mirror
#!/bin/bash
# PULL
docker login gitrra.dyndns.org:4443
docker login git.rra.lan:4443
FROM=gitrra.dyndns.org:4443/rra/pdgrt/deployment/
TO=git.rra.lan:4443/pdgrt_2.0_mirror/deployment/
REPOS="pdgrt-central-frontend pdgrt-proxy-frontend pdgrt-node-frontend pdgrt-proxy-backend/django pdgrt-proxy-backend/nginx pdgrt-node-backend/django pdgrt-node-backend/nginx pdgrt-central-backend/django pdgrt-central-backend/nginx"
for repo in ${REPOS}; do
docker pull ${FROM}${repo}
docker tag ${FROM}${repo} ${TO}${repo}
docker push ${TO}${repo}
done