Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
https://portainer.io/overview.html

Manage your docker ecosystem by Portainer.

#container #docker #dashboard
PART-1: Basic docker commands

* Let's suppose you have built an image.

Display list of your docker images:
docker images


Output:
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
py_app latest baa470dc5609 3 weeks ago 591MB


As you can see image name is py_app.

To run the image:
docker run -it -d -p 8085:8084 py_app


The above command runs the docker image. The newly created processs by docker run from your py_app image is called a container. -d runs the image as a daemon and print the container id to your console:
$ docker run -it -d -p 8085:8084 py_app
d612ffbd9d560158f1c64997f9a8877243cdf4288c11010298df80b10cfaff5e


-p exposes the port on your docker file to the port on your host machine. The first port 8085 is the port on your
host, and the second port 8084 is the port on your docker file.

Now to see list of your containers use docker ps:
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d612ffbd9d56 py_app "python app.py" 10 minutes ago Up 10 minutes goofy_hopper


From here you can see the ID of your container which is equal to d612ffbd9d56. IF you want to have a shell on your c
ontainer (login into container):
docker exec -it d612ffbd9d56  bash
root@moby:/app#


if you want to connect to the stdout of your container use attach, it does not necessary give you a shell:
docker attach d612ffbd9d56

*** IF you are attached to a container and press ^c afterward, the container will be stopped.

If you want to stop a container:
$ docker stop d612ffbd9d56
d612ffbd9d56


It prints out container id d612ffbd9d56 and stop the container. If you enter docker ps you should not see the container.

#docker #commands #docker_part1 #basic #container #devops
Run a bash in your container:
sudo docker exec -i -t 96885e9e9a51 /bin/bash

96885e9e9a51 is container id. You have to find it yourself by using the below command:
docker ps -a

#docker #exec #bash #container
Pass arguments to Dockerfile when you build it using --build-arg in order to have greater flexibility on docker build:
docker build -t essearch/ess-elasticsearch:1.7.6 --build-arg SHARDS_NO=5

If you want to pass multiple arguments to Dockerfile give another --build-arg and give your second argument as above.
Now initiate your args inside of Dockerfile as below:
ARG SHARDS_NO=""

#docker #container #build_arg #argument #build #image
If you get the below error for cross device link when installing npm on container:
npm WARN optional Skipping failed optional dependency /webpack/watchpack/chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.0.12
npm ERR! Linux 3.16.0-4-amd64
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v6.3.0
npm ERR! npm v3.10.3
npm ERR! path /app/node_modules/istanbul/node_modules/abbrev
npm ERR! code EXDEV
npm ERR! errno -18
npm ERR! syscall rename

npm ERR! EXDEV: cross-device link not permitted, rename '/app/node_modules/istanbul/node_modules/abbrev' -> '/app/node_modules/abbrev'
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR! /app/npm-debug.log
The command '/bin/sh -c npm install' returned a non-zero code: 238


To solve this problem, put the below line of code before any npm command:
RUN cd $(npm root -g)/npm && npm install fs-extra && sed -i -e s/graceful-fs/fs-extra/ -e s/fs.rename/fs.move/ ./lib/utils/rename.js


reference: https://github.com/npm/npm/issues/13306
#npm #docker #container #cross_device
Let's run a MySQL instance on our local machine using docker. You don't need to install any version of mysql on your system. You won't get into trouble of upgrading the mysql or even in the trouble of removing it.

When you stop the container Mysql will be stopped. If you remove the image it will be gone forever :)

To run an instance of mySQL on your system (server or desktop), just use the below command:
docker run -p 3306:3306 --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:latest

NOTE: we assume that docker is installed on your system.

-p 3306:3306 will bind the container port into a port in host machine. We run it on 3306, if you have to change it you need to change the first port number to a port in your host like 3350:3306.

--name gives a name to you container, so you can easily work with the name provided.

-e will set an environment variable. Here we have set a password for our mysql root user.

-d makes the container to be run in DAEMON mode (in background).

mysql:latest this is the image name that you will pull from docker hub registry.

Voila! You are up & running we a totally working mysql server.

Let's check with netstat (on your HOST) whether it's up or not:
root@infra:~# netstat -nltp | grep 3306
tcp6 0 0 :::3306 :::* LISTEN 11572/docker-proxy

#docker #mysql #netstat #image #container
How to get IP address of a docker container?

First you need to issue the following command to get the container id (first column):
docker ps

Use the container ID to run:
docker inspect <container ID>

At the bottom,under NetworkSettings, you can find IPAddress.

#docker #ip_address #container #ps #ip #inspect
Netflix has open sourced his container management system called Titus written in Go Lang. You can see documentation of it here:

- https://netflix.github.io/titus/

Source code and Docs:

- https://github.com/Netflix/titus

#container_orchestration #docker #container #golang #go #netflix #titus #aws