Docker =============================== ******************************************************************************** ## Install Docker ******************************************************************************** ###on-ubuntu-16-04 source : https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04 sudo apt-get update sudo apt-key adv –keyserver hkp://p80.pool.sks-keyservers.net:80 –recv-keys 58118E89F3A912897C070ADBF76221572C52609D echo “deb https://apt.dockerproject.org/repo ubuntu-xenial main” | sudo tee /etc/apt/sources.list.d/docker.list sudo apt-get update apt-cache policy docker-engine You should see output similar to the follow: Output of apt-cache policy docker-engine docker-engine: Installed: (none) Candidate: 1.11.1-0~xenial Version table: 1.11.1-0~xenial 500 500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages 1.11.0-0~xenial 500 500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages sudo apt-get install -y docker-engine sudo systemctl status docker The output should be similar to the following, showing that the service is active and running: Output ● docker.service – Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2016-05-01 06:53:52 CDT; 1 weeks 3 days ago Docs: https://docs.docker.com Main PID: 749 (docker) ###Executing the Docker Command Without Sudo (Optional) sudo usermod -aG docker $(whoami) now you must logout to ensure all privilage is write ******************************************************************************** ## RUN or START ******************************************************************************** run : runs an image start : starts a container. The docker run doc does mention: The docker run command first creates a writeable container layer over the specified image, and then starts it using the specified command. That is, docker run is equivalent to the API /containers/create then /containers/(id)/start. You do not run an existing container, you docker exec to it (since docker 1.3). You can restart an exited container. ******************************************************************************** ## Docker HUB ******************************************************************************** https://hub.docker.com/ ******************************************************************************** ## MySQl and WordPress with Docker ******************************************************************************** docker run -v /var/lib/mysql –name farid-some-mysql -e MYSQL_ROOT_PASSWORD=zanjan -e MYSQL_DATABASE=wordpress -d mysql docker run -it -v /home/sinic/wordpress:/var/www/html/wp-content/ -p 8080:1395 –name farid-some-ubuntu3 –link farid-some-mysql:mysql ubuntu/apache:wordpress ### How To Use MYSQL in Wordpress container define(‘DB_NAME’, exec(‘echo $MYSQL_DATABASE’)); /** MySQL database username */ define(‘DB_USER’, ‘root’); /** MySQL database password */ define(‘DB_PASSWORD’, exec(‘echo $MYSQL_ENV_MYSQL_ROOT_PASSWORD’)); /** MySQL hostname */ define(‘DB_HOST’, exec(‘echo $MYSQL_PORT_3306_TCP_ADDR’)); /** Database Charset to use in creating database tables. */ define(‘DB_CHARSET’, ‘utf8’); /** The Database Collate type. Don’t change this if in doubt. */ define(‘DB_COLLATE’, ”); ******************************************************************************** ## How To MONITOR containers ******************************************************************************** docker ps docker ps -a docker stats ******************************************************************************** ## How To Copy files in a container ******************************************************************************** docker cp Downloads/wordpress-4.5.2-fa_IR.zip kickass_thompson:/var/www/html ******************************************************************************** ## Export and Import Images ******************************************************************************** You will need to save the docker image as a tar file: docker save -o Then copy your image to a new system with regular file transfer tools such as cp or scp. After that you will have to load the image into docker: docker load -i PS: You may need to sudo all commands. ******************************************************************************** ## Networking modes ******************************************************************************** docker run –net=”bridge” (default) docker run –net=”host” ******************************************************************************** ## Detach fron a running container ******************************************************************************** If you do “docker attach “container id” you get into the container. To exit from the container without stopping the container you need to enter “Ctrl+P+Q” better to Ctrl+P and Ctrl+Q ******************************************************************************** ## Open new shell in a container ******************************************************************************** docker exec -it sinic-osticket bash ******************************************************************************** _BY: Farid Ahmadian_ _TAG: docker_ _DATE: 2016-08-1 10:36:53_