docker install and use



install docker from

https://docs.docker.com/install/linux/docker-ce/ubuntu/

change directory containers

first create the folder

Terminal:
mkdir /home/$USER/docker-files/

copy all elements to new folder
Terminal:
sudo rsync -aXS /var/lib/docker/. /home/$USER/docker-files/

create a point mount in fstab
Terminal:
/home/$USER/docker-files/ /var/lib/docker none bind 0 0

Now mount of new configuration without reboot.
Terminal:
mount -a


Enabled autostart dockerd
Terminal:
sudo systemctl enable docker

edit file config service docker
Terminal:
nano /etc/systemd/system/multi-user.target.wants/docker.service

change ExecStart
Terminal:
ExecStart=/usr/bin/dockerd -H unix:// -H tcp://0.0.0.0:2375

reload files systemctl
Terminal:
sudo systemctl daemon-reload

add your user to group docker
Terminal:
sudo usermod -aG docker $USER


ready dockerd auto run now

now check the system to install
Terminal:
docker search ubuntu


now install the server
Terminal:
docker pull ubuntu


now run the server
Terminal:
docker run -i -t ubuntu /bin/bash 

show the containers
Terminal:
docker ps -a

copy the id of you container

example:
CONTAINER ID        IMAGE               COMMAND                 CREATED             STATUS                         PORTS               NAMES
6b1b845eae6a        cirel/ubuntu2       "/bin/bash"             2 minutes ago       Exited (0) 2 minutes ago     


descargar imagenes
Terminal:
sudo docker pull debian:jessie

docker images
Terminal:
docker images


Terminal:
docker commit 6b1b845eae6a cirel/ubuntu2


now check the container change, if you can run again you container use
Terminal:
docker run -it cirel/ubuntu2 /bin/bash





Terminal:
docker -it -d 1483112e529b /bin/bash

if want remove container
Terminal:
docker rm ID-CONTAINER



if want remove image
Terminal:
docker rm ID-IMAGE


remove all containers
Terminal:
docker rm $(docker ps -a -q)





problems with locale in container
Terminal:
apt-get install -y locales

Terminal:
dpkg-reconfigure locales

Terminal:
sed -i 's/^# *\(en_US.UTF-8\)/\1/' /etc/locale.gen && locale-gen

Terminal:
locale-gen en_US.UTF-8












Docker compose

Terminal:
sudo apt-get purge python-pip

Terminal:
sudo wget https://bootstrap.pypa.io/get-pip.py

Terminal:
sudo python get-pip.py

Terminal:
pip uninstall autopep8 pep8

Terminal:
pip install docker-compose

Terminal:
sudo docker-compose up



check files container
Terminal:
docker exec -it container_name bash

docker backup pgsql
Terminal:
docker exec -t your-db-container pg_dumpall -c -U postgres > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql

or

Terminal:
docker exec -t your-db-container pg_dump --no-owner --no-acl -U drupal drupal > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql

docker restore pgsql
Terminal:
cat your_dump.sql | docker exec -i your-db-container psql -U postgres

docker compose remove container with name image
Terminal:
sudo docker-compose rm postgresql



docker mysql

backup mysql
Terminal:
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
Terminal:
docker exec -i mysql-5.6-new /usr/bin/mysqldump -u default --password=default --default-character-set=utf8 --all-databases  --routines  > alldb.sql


restore mysql
Terminal:
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
Terminal:
docker exec -i CONTAINER /usr/bin/mysql --default-character-set=utf8 DATABASE -u default --password=default < /tmp/BACKUP_DATA_BASE

Docker restar and show logs container
Terminal:
DOCKER_CONTAINER="nginx" && sudo docker container restart $DOCKER_CONTAINER && sudo docker container logs -f -t --tail 40 $DOCKER_CONTAINER


Docker list containers running
Terminal:
docker ps

Docker list stats containers running
Terminal:
docker stats


keep running docker in command exec
Terminal:
tail -f /dev/null



docker error memory limit

Terminal:
sudo sysctl -w vm.max_map_count=262144

docker remove logs

Terminal:
sudo find /var/lib/docker/containers/ -type f -name "*.log" -delete


https://www.elastic.co/guide/en/elasticsearch/reference/5.0/vm-max-map-count.html#vm-max-map-count



Fuente: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04

http://alexander.holbreich.org/moving-docker-images-different-partition/











0 comentarios :