Docker Installation and install Database on docker

Install docker


sudo apt install docker.io


Basic commands

  1. Check Current running container

    docker ps

  2. Shows all containers

    docker ps -a 

  3. Stop container

    docker stop container-id

  4. Check Docker version

    docker --version

  5.  Pull docker image docker hub

    docker pull mysql:latest


    -d - daemon run on background

    -e - environment variable

    3306:3306 mysql default port 

Create a new container/ instance with an image

MySQL

sudo docker run --name mysql -d -e MYSQL_ROOT_PASSWORD=password -p 3306:3306 mysql:latest

# Run on different port

sudo docker run --name mysqlDocker -d -e MYSQL_ROOT_PASSWORD=password -p 3000:3306 mysql:latest


# Command client

sudo docker exec -it db /bin/bash

mysql -u root -ppassword

MariaDB

docker run --name mariadbDocker -e MYSQL_ROOT_PASSWORD=mypass -p 4000:3306 -d docker.io/library/mariadb

Connect to mariadb

docker exec -it mariadbDocker mariadb --user root -pmypass

PostgreSQL


docker run --name postgres12 -p 5432:5432 -e POSTGRES_USER=root -e POSTGRES_PASSWORD=password -d postgres:12-alpine

Login into postgres bash:

sudo docker exec -it 29aab9f62f34 psql -U postgres


Cockroachdb

docker run -d --name cockroachdb -p 26257:26257 -p 8080:8080 cockroachdb/cockroach:latest start-single-node --insecure

docker exec -it cockroachdb bash

cockroach sql --insecure

create user test WITH LOGIN PASSWORD 'password';


Redis

docker run --name redis -d -p 6379:6379 redis redis-server --requirepass "password"

docker exec -it 9e6b10a028c0 bash

cli :  redis-cli -a "password"

Install Docker Compose  latest :

sudo curl -SL https://github.com/docker/compose/releases/download/v2.11.2/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose


sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose


sudo chmod +x /usr/local/bin/docker-compose


docker-compose version


Dump sql for mysql,mariadb into docker 

docker exec -i mysqlDocker mysql -uroot -pmypass test < ad_resources21423.sql

docker exec -i mariadbDocker mariadb -uroot -pmypass dev_ad_resources < ad_resources21423.sql

Run Docker without sudo : 


1. sudo usermod -aG docker username

2. su - username

3. sudo usermod -aG docker username

Comments