Master Docker with DevOpsRoles.com. Discover comprehensive guides and tutorials to efficiently use Docker for containerization and streamline your DevOps processes.
In this tutorial, How to install Docker compose on Ubuntu 21.04. Docker is an open platform that allows you to build, test, and deploy applications quickly.
Docker Compose is used for defining and running multi-container Docker applications. It allows users to launch, execute, communicate with a single coordinated command. Docker Compose is yet another useful Docker tool.
Prerequisites
A system running Ubuntu 21.04
A user account with sudo privileges
Docker installed on Ubuntu 21.04
Step 1: Update your system
Update your existing packages:
sudo apt update
Step 2: Install curl package
sudo apt install curl -y
Step 3: Download the Latest Docker compose Version
This tutorial explains how to install Docker on Ubuntu 21.04, highlighting Docker as an efficient open platform for building, testing, and deploying applications. Docker simplifies and accelerates the deployment process, making it less time-consuming to build and test applications. The guide is ideal for anyone looking to streamline their development workflow using Docker on the Ubuntu system.
How to install Docker on Ubuntu
To install Docker on Ubuntu, you can follow these steps:
How to install Docker on Ubuntu 21.04. After completing these steps, Docker should be successfully installed on your Ubuntu system, and you can start using Docker commands to manage containers and images. I hope will this your helpful. Thank you for reading the DevopsRoles page!
In this tutorial, We will deploy a container Nginx server, modify it, and then create a new image from that running container. Now, let’s go to Create Docker Image from a Running Container.
What does docker mean?
Docker is a set of platform as a service products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries, and configuration files Quota from Wikipedia
Install Docker on Ubuntu
If you don’t already have Docker installed, let’s do so. I will install Docker on Ubuntu Server. I use Ubuntu version 21.04 to install Docker.
To install Docker on Your Ubuntu server command below
sudo apt-get install docker.io -y
Add your user to the docker group with the command below
sudo usermod -aG docker $USER
Logging out and logging back in to ensure the changes take effect.
Create Docker Image from a Running Container
Create the New Container
We will create the new container with the command below:
vagrant@devopsroles:~$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fe3d2e383b80 nginx:alpine "/docker-entrypoint.…" 11 minutes ago Up 8 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp nginx-devops
vagrant@devopsroles:~$ sudo docker stop fe3d2e383b80
fe3d2e383b80
vagrant@devopsroles:~$ sudo docker rm fe3d2e383b80
fe3d2e383b80
vagrant@devopsroles:~$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
vagrant@devopsroles:~$ sudo docker create --name nginx-new -p 80:80 nginx-devops-container:latest
91175e61375cf86fc935c55081be6f81354923564c9c0c0f4e5055ef0f590600
vagrant@devopsroles:~$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
91175e61375c nginx-devops-container:latest "/docker-entrypoint.…" About a minute ago Created nginx-new
vagrant@devopsroles:~$ sudo docker start 91175e61375c
91175e61375c
vagrant@devopsroles:~$
What is the difference between docker commit and docker build?
docker commit creates an image from a container’s state, while docker build creating an image from a Dockerfile, allowing for a more controlled and reproducible build process.
Refresh your web browser and you should, once again, see the DevopsRoles page, New Stack! Welcome page.
YouTube: Create Docker Image from a Running Container
Conclusion
Create Docker Image from a Running Container is a powerful feature that enables you to capture the exact state of an application at any given moment. By following the steps outlined in this guide, you can easily commit a running container to a new image and use advanced techniques to add tags, commit messages, and author information. Whether you’re looking to back up your application, replicate environments, or share your work with others, this process provides a simple and effective solution. I hope will this your helpful. Thank you for reading the DevopsRoles page!
In today’s fast-paced development environments, the ability to quickly deploy and manage databases is crucial. Docker provides a powerful solution for running PostgreSQL databases in isolated containers, making it easier to develop, test, and deploy your applications. In this tutorial, you will learn how to use Docker run PostgreSQL databases and connect to them, enabling you to efficiently manage your database environments with minimal setup. Whether you’re new to Docker or looking to streamline your database management, this guide will equip you with the essential knowledge to get started.
PostgreSQL is a powerful, open-source object-relational database
Docker is an open platform that runs an application in an isolated environment called a container.
Your database is currently empty. I will create a table as an example
CREATE TABLE sites (id SERIAL PRIMARY KEY, name VARCHAR(100));
INSERT INTO sites (name)
VALUES ('devopsroles.com'), ('huuphan.com');
I will run a command to query the table created.
SELECT * FROM sites;
The output terminal is below
Docker Manage data persistence
The problem is that we stop and start the container with the commands “docker stop my-postgres-db” and “docker start my-postgres-db” when creating a new container will not allow us to access the database that you are created, as it was isolated in your container.
Create a new volume with the following command. The solution stores the database outside of the container
docker volume create my-postgres-db-db
You will stop and remove your current container and create a new one.
How to know where the database is stored on your computer
docker inspect my-postgres-db-db
The output terminal is below
Link Youtube: Docker run PostgreSQL
Conclusion
Using Docker to run PostgreSQL databases offers a streamlined approach to managing your database environments with ease and efficiency. I hope this tutorial has provided you with the necessary insights and steps to confidently set up and connect to PostgreSQL using Docker. Thank you for reading the DevopsRoles page and I hope this guide proves helpful in your journey toward optimizing your development and deployment processes.
In this tutorial, How to deploy Flask-MySQL app with docker-compose. From the official docs. Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration. The fist, You need to install Docker and docker-compose. Next, we will Deploy Flask-MySQL app.
[vagrant@localhost docker-flask-app]$ cat db/init.sql
create database devopsroles;
use devopsroles;
CREATE TABLE test_table (
name VARCHAR(20),
color VARCHAR(10)
);
INSERT INTO test_table
(name, color)
VALUES
('dev', 'blue'),
('pro', 'yellow');
Create a Docker image for Flask app
Create a Dockerfile file in the app folder.
[vagrant@localhost docker-flask-app]$ cat app/Dockerfile
# Use an official Python runtime as an image
FROM python:3.6
# The EXPOSE instruction indicates the ports on which a container
EXPOSE 5000
# Sets the working directory for following COPY and CMD instructions
# Notice we haven’t created a directory by this name - this instruction
# creates a directory with this name if it doesn’t exist
WORKDIR /app
COPY requirements.txt /app
RUN python -m pip install --upgrade pip
RUN pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host=files.pythonhosted.org --no-cache-dir -r requirements.txt
# Run app.py when the container launches
COPY app.py /app
CMD python app.py
You need dependencies Flask and mysql-connector in File requirements.txt
[vagrant@localhost docker-flask-app]$ docker-compose up -d
The result, after running the Flask app
FAQs
1. What is Docker-Compose?
Docker-Compose is a tool for defining and running multi-container Docker applications. It allows you to configure your application’s services in a YAML file and start all services with a single command.
2. How can I persist data in MySQL?
In the Docker-Compose file, the db_data volume ensures that the data in MySQL is persisted even if the container is stopped.
3. Can I use a different database with Flask?
Yes, Flask can work with various databases like PostgreSQL, SQLite, and more. You need to adjust the connection setup in your Flask app and Docker-Compose file accordingly.
Conclusion
You have Deploy Flask-MySQL app with docker-compose. I hope will this your helpful. Thank you for reading the DevopsRoles page!
In this tutorial, I will install Odoo version 13/14 on Docker Container. Odoo is a suite of well-known open-source business software that covers all your company needs: CRM, eCommerce, inventory, point of sale, project … Next, we will install Odoo on Docker Container
Install Odoo on Docker Container
OS Host: Centos 7
Docker image: odoo:14 and Postgres
Install Odoo Docker Image
To install Odoo use the command below:
#For odoo version 14
docker pull odoo:14
# For Oddo 13
docker pull odoo:13
Install PostgreSQL Database Docker Image
Use the command below:
docker pull postgres
The output terminal is as follows:
Create Database Container
docker run -d -v odoo-db:/var/lib/postgresql/data -e POSTGRES_USER=odoo -e POSTGRES_PASSWORD=odoo -e POSTGRES_DB=postgres --name db postgres
Note:
odoo-db:/var/lib/postgresql/data – store the database data. This means after remove the container, odoo data will remain.
POSTGRES_USER=odoo– A User created for database
POSTGRES_PASSWORD=odoo – Password for the created database user
In this tutorial, How to Pass environment variables to Docker containers. You need to pass environment variables to docker containers as a running instance of Docker. I use Docker images Postgres Databases.
Set environment variables to Docker containers
We will set a variable DB_USER and DB_PASSWORD as follows: