Git Product home page Git Product logo

docker-mysql's Introduction

Docker

Required

or

  • Docker ubuntu

Uninstall older versions sudo apt-get remove docker docker-engine docker.io containerd runc

Install last version sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin


First example

Create MySQL container and use with MySQL Workbench

Steps

If using docker desktop be sure you have it up and running

Pull image of mysql

  1. First step is to look for the image in the Docker Hub

docker hub mysql image

  1. Here we will be using the latest mysql image available we pull the image using the command docker image pull

docker mysql image pull

  1. After the download is completed we verify the image using the command docker images

docker mysql image verification

Create and Run the container of mysql

  1. To create and run the container of mysql we can use the command docker container run here we provide the container name, environment variables, define localhost port, to run in background mode and the image of mysql

docker mysql create container

  1. This will provide a container id and we can verify the container using the command docker ps . We see that container id correspond to the container small id and the port 3306 of our host is mapped to the port 3306 of the container

docker mysql create container

  1. Finally we can use MySQL Workbench to verify our container is up and running. We provide the hostname: localhost port: 3306 username: root and password: root .

docker mysql create container

docker mysql create container

4.- At end we can stop the container execution using the command docker container stop , remove container using the command docker container rm , and remove image of mysql using the command docker image rm .

docker mysql remove container


Second example

Create MySQL container and use with Adminer container

Steps

If using docker desktop be sure you have it up and running

Pull image of mysql

  1. First step is to look for the image in the Docker Hub

docker hub mysql image

  1. Here we will be using the latest mysql image available we pull the image using the command docker image pull

docker mysql image pull

  1. After the download is completed we verify the image using the command docker images

docker mysql image verification

Pull image of adminer

  1. First step is to look for the image in the Docker Hub

docker hub adminer image

  1. Here we will be using the latest adminer image available we pull the image using the command docker image pull

docker adminer image pull

  1. After the download is completed we verify the image using the command docker images

docker adminer image verification

Create and Run the container of mysql

  1. To create and run the container of mysql we can use the command docker run here we provide the container name, environment variables, define localhost port, to run in background mode and the image of mysql

  2. This will provide a container id and we can verify the container using the command docker ps . We see that container id correspond to the container small id and the port 3306 of our host is mapped to the port 3306 of the container

docker mysql create container

Create and Run the container of adminer

  1. To create and run the container of adminer we can use the command docker run here we provide the container name, link to another container, define localhost port, to run in background mode and the image of adminer

  2. This will provide a container id and we can verify the container using the command docker ps . We see that container id correspond to the container small id and the port 3306 of our host is mapped to the port 3306 of the container

docker mysql create container

Check connection of adminer and mysql

We link the container of adminer to the container of mysql using the option --link. Now we can access to localhost:8080 and set params System: MySQL, Server: mysqlito, Username: userdb, password: passworddb, Database: mysqldb.Those where defined in mysql container creation.

adminer connection

adminer connection

Stop containers, remove it and remove images

  1. Finally we can stop containers with command docker stop

  2. Remove containers with command docker rm

  3. Verify containers are removed with command docker ps -a

  4. Remove images with command docker image rm

  5. Verify images are removed with command docker images

remove containers and images


Third example

Now we are going to use docker-compose

This will help us to download images, create, (re)build, starts multi-containers all of that with a single file and command

Steps

If using docker desktop be sure you have it up and running

Create docker-compose.yml (define multi-container application)

docker-compose.yml example file

docker-compose.yml file allows you to configure and document all your application's service dependencies (other services, cache, databases, queues, etc.). Using the docker-compose CLI command, you can create and start one or more containers for each dependency with a single command (docker-compose up).

What is defined in the file are this:

  • version Specifies the version of the Docker Compose syntax to be used in the file.
  • services Defines the individual services (containers) that make up the application. Each service is specified as a key-value pair, where the key is the name of the service and the value is a set of properties that configure the service. Properties can include the Docker image to be used, environment variables, ports to be exposed, volumes to be mounted, and other configurations.
  • networks Defines the networks to be used by the services. Networks enable communication between different services within the same Docker Compose application.
  • volumes Defines the volumes to be used by the services. Volumes are used to persist data across container restarts or to share data between containers.
  • configs and secrets Define configurations and secrets to be used by the services. Configurations and secrets are used to externalize configuration data and sensitive information, respectively, from the docker-compose.yml file.
  • deploy Specifies configurations related to deployment of the services in a swarm mode Docker cluster, such as replicas, placement constraints, and update policies.
  1. To pull required images we use command docker-compose pull this will pull images defined in docker-compose.yml

docker-compose pull

  1. We verify the images downloaded docker image ls

docker-compose pull

  1. Now to run the containers defined in docker-compose we use the command docker-compose up -d this will create and start the containers.

docker-compose pull

  1. We can verify in localhost:8080 and set params System: MySQL, Server: mysqlito, Username: userdb, password: passworddb, Database: mysqldb.Those where defined in mysql container creation.

docker-compose pull

docker-compose pull

Stop containers, remove it and remove images

  1. Finally we can stop containers with command docker stop

  2. Remove containers with command docker rm

  3. Verify containers are removed with command docker ps -a

  4. Remove images with command docker image rm

  5. Verify images are removed with command docker images

remove containers and images

docker-mysql's People

Contributors

brandonruizmora avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.