DOCKER INSTALLATION PROCESS:

To install Docker on Ubuntu, in the terminal window enter the command

 

$ sudo apt install docker.io

The Docker service needs to be setup to run at startup

 

$ sudo systemctl start docker

$ sudo systemctl enable docker

To verify the installed Docker version number

$ docker –version

Alternative: Install Docker from Official Repository

Download Dependencies

 Docker mysql :

$ docker run –name=test-mysql mysql

Run –>for run the container

–name –> container name

Check the containers

$ docker ps –>show the running  containers

$docker images —>docker hub

$ docker ps -a –>status check

$ docker run –name=test-mysql –env=”MYSQL_ROOT_PASSWORD=mypassword” mysql —> name based create mysql

$ docker rm test-mysql —> remove the test-mysql

$ docker stop test-mysql –> stop the container

$ docker logs test-mysql → mysql container logs check

 

 

Connecting to the Container

$ docker inspect test-mysql –> you can see the ip address

    “IPAddress”: “172.17.0.20”,

$ apt-get install mysql-client

$mysql -u root -p **** -h  -p 3306

 

$ip a | grep docker | grep inet

$docker stop test -mysql

$docker start test-mysql

Docker introduces another way to link your container with another container

 

$ docker run –detach –name test-wordpress –link test-mysql:mysql wordpress

 

$ docker ps –> check the linked container

 

$ docker exec -it test-wordpress bash –> run bash mode

 

$ docker rm -f test-mysql

$ docker run –detach –name=test-mysql –env=”MYSQL_ROOT_PASSWORD=mypass

 

 

 

Configuration content

Container configuration file

/etc/mysql/conf.d –> Inside container location

 

$ mysql -u root -p ***** -h 173.23.1.345 -p 3306

 

Node Install process in docker

$

Install NPM and Express Framework

Create a new directory and initialize npm and directory to store files, run npm, and launch our application:

 

$ mkdir helloworld

$ cd helloworld

$ npm init

Install Express

Setup basic express server. The file below simply says to start a Node process that listens to port 3000 and responds with Hello World!

  $ npm install –save-prod express

src/index.js

The Docker-compose.yml file in order to start and stop our Docker containers as opposed to typing long Docker commands. You can think of this file as a config file for multiple Docker containers.

start the docker container with this command. This just means start the containers defined in our config file and run them in the background (-d)

                  $ docker-compose up -d

verify that your container is running

http://localhost:3000

 

    $ docker ps

            

               Start & Stop containers from a docker-compose.yml file in the same directory

$ docker-compose up -d

               $ docker-compose stop

$ docker-compose restart

See the log files from your docker container

    $ docker-compose logs -f

Install PM2

PM2 can be used through the command line docker-compose.yml

$ npm install –save-prod pm2

 

Ecosystem.config.js

              

                             

change our docker-compose.yml file to use PM2 to start our app

instead of starting it directly from index.js.

           

               $ docker-compose restart

             ecosystem.config.js (only added the watch option)**

             

Install NPM and Express Framework

              $  docker exec -it app bash

                  The above command will put you inside the container so you can continue to run your 

commands from there i.e. npm run start or npm run test

                          $ docker exec -t app bash -c “npm run start”

 

Reference:

https://severalnines.com/blog/mysql-docker-building-container-image

https://dev.to/itmayziii/step-by-step-guide-to-setup-node-with-docker-2mc9

 

Categories: Uncategorized