Showing posts with label docker. Show all posts
Showing posts with label docker. Show all posts

Thursday, November 14, 2024

How to install oracle database on Ubuntu system with Docker

In this tutorial, we are going to learn how to install the Oracle database on the Ubuntu system.

- Prerequisites

Docker needs to be installed on the system to verify it use the following command

docker --version

This will list the docker version installed

elint@elint:~$ docker --version
Docker version 27.0.2, build 912c1dd

- Download the Oracle docker image

Next, download or clone the oracle docker image from the repo oracle/docker-image Unzip it.

Navigate to the Oracle database docker files; in our case, it's inside /opt/oracle/docker-images/OracleDatabase/SingleInstance/dockerfiles. Here, you can see all the dockerfiles version. Select and navigate the desired version to install

- Download the Oracle database binary file

Download the database zip file from the Oracle website This will require the Oracle login so, create the account login and download the file. Once downloaded copy that file under the Oracle database selected dockerfile version. In our case, we are using docker file version 19.3.0

The overall folder structure looks like below

- Build the Oracle docker image

Note: You need to have at least 8-15Gb storage space on your system

Navigate to the folder

cd /opt/oracle/docker-images/OracleDatabase/SingleInstance/dockerfiles/19.3.0

Using the following command to build

docker build -t oracle/database:19.3.0-ee --build-arg DB_EDITION=ee .

Here oracle/database:19.3.0-ee is the image name, you can give any name

or you can use the following command

../buildContainerImage.sh -v 19.3.0 -e

-v specifies the docker image version and -e for the enterprise edition

Note: this will take some time to build the image

- Run the Oracle container

docker run --name oracle19.3c --network host -p 1521:1521 -p 5500:5500 -v /opt/oracle:/home/oracle oracle/database:19.3.0-ee

This will take some time to complete according to your system's RAM and CPU. Once completed the output looks similar as below

You can close the terminal after this.

- Start the container

To start the container run the below command

docker start oracle19.3c

oracle19.3c is the container name; you can find it using the command: docker ps -a

elint@elint:/opt/oracle/docker-images/OracleDatabase/SingleInstance/dockerfiles/19.3.0$ docker ps -a 
CONTAINER ID   IMAGE                       COMMAND                  CREATED       STATUS                 PORTS     NAMES
767c0a92e087   oracle/database:19.3.0-ee   "/bin/bash -c 'exec …"   11 days ago   Up 11 days (healthy)             oracle19.3c

This process will set the default username and password for the system user to change it, use the command

docker exec oracle19.3c ./setPassword.sh yourPassword

Where oracle19.3c is the container name

Now, login into the container

docker exec -it oracle19.3c bash

To connect to the database use the below command

sqlplus system/yourPassword@orclpdb1

Here orclpdb1 is the default database SID created

If you are having trouble running queries with sqlplus might be due to the export path issue that can resolved by exporting the environment variable. Note: enter into the container first with the command: docker exec -it oracle19.3c bash

export ORACLE_HOME=/opt/oracle/product/19c/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH

Verify the path for sqlplus

bash-4.2$ cd /opt/oracle/product/19c/dbhome_1 
bash-4.2$ ls
OPatch	 addnode     cfgtoollogs  css  data    deinstall    drdaas   has      instantclient  jdbc  ldap  md	  nls	opmn	     ord  owm	 precomp  relnotes     root.sh.old.1  runInstaller   slax      sqlplus	utl
QOpatch  assistants  clone	  ctx  dbjava  demo	    dv	     hs       inventory      jdk   lib	 mgw	  odbc	oraInst.loc  oss  perl	 racg	  root.sh      root.sh.old.2  schagent.conf  sqlj      srvm	wwg
R	 bin	     crs	  cv   dbs     diagnostics  env.ora  install  javavm	     jlib  log	 network  olap	oracore      oui  plsql  rdbms	  root.sh.old  root.sh.old.3  sdk	     sqlpatch  usm	xdk

Now you can create a new sid/database and connect to the users.

With suitable database connector; you can connect the database using the url: jdbc:oracle:thin:@127.0.0.1:1521/orclpdb1

Share:

Wednesday, November 13, 2024

How to remove docker containers and images

In this tutorial, we are going to learn how to remove the docker containers and images

Initially, list all the containers that use the docker images. To see all the running containers on your machine use the following command

docker ps -a

This will show all the running containers on your machine. The sample output looks like as below:

Here, we do have one running container with container ID: 767c0a92e087 and container name: oracle19.3c

Stop a running container

docker stop <container_id>

Use your own container ID in our case it is 767c0a92e087 to stop it

Now, let's delete the container

docker rm <container_id>

To force to remove the running container in one command use the following command

docker rm -f <container_id>

If you want to remove all the containers(not recommended)

docker container prune

Let's look into deleting the docker images

List all the available docker images

docker image ls

The sample output looks like

elint@elint:~$ docker image ls
REPOSITORY        TAG         IMAGE ID       CREATED       SIZE
oracle/database   19.3.0-ee   dd6c130762a3   11 days ago   6.54GB

To delete the specific image

docker rmi <image_id>

Use your own docker image ID in our case it is dd6c130762a3

To remove the docker image forcefully

docker rmi -f <image_id>

To remove unused images. The unused or dangling images are those images which are not associated with docker images

docker image prune

Note: the deleted images need to re-download if we need it later

These are the overall commands to clean up the docker containers and images.

Share:

Wednesday, July 27, 2022

Install Mysql in Docker on Ubuntu Linux server

In this tutorial, we will learn how to install Mysql on Docker.

Please follow the steps to install docker using this tutorial Install Docker on Ubuntu

Install Mysql using Docker:

To install the desired version of MySQL first, visit docker mysql image section where we can find the available MySQL version. In this tutorial, we are using MySQL version 5.7.

Use the following command on the server to install the MySQL image

docker pull mysql:5.7 

Use your own version instead of 5.7

This will pull the image and install Mysql inside docker. We can verify the image using the following command

docker images

The output of the above command will be similar to this

mysql          5.7                   314749b3a5c   17 hours ago    431MB

Create Mysql Container:

Let’s create the MySQL container. To create a MySQL container, use the following command.

docker run --name=cn-mysql -d -p 3316:3306 --env="MYSQL_ROOT_PASSWORD=root1249" mysql:5.7

Note: use your own MySQL root password instead of root1249 and the port instead of 3316 and container name instead of cn-mysql

This will create the container. We can see the container using the following command

docker container ls -a 
OR
docker ps -a

Enter into the Mysql server:

If we want to do the regular MySQL operation, then we need to enter the MySQL server inside docker as below

docker exec -it elint-mysql bash

Now login into MySQL using the command

mysql -u root -p

Use your own MySQL password which is used while creating a container i.e root1249

Now we can do operations like creating databases and users.

Creating Mysql User:

In order to create a MySQL user and give permission visit the tutorial, Create Mysql User and Grant Privileges

Let's create a user

create user 'username'@'%' identified by 'password';

Note: change your own username and password. If you need to connect your created user from any client, you should create the user with “%” which signifies, that you can connect this user from any host.

Now, let's grant privileges

grant all privileges on *.* to username;

Use the previously created username

flush privileges;
Share:

Install Docker on Ubuntu 20.04

In this tutorial, we will learn how to install docker on Ubuntu Linux.

Install docker using the repository:

For this, first set up the repository. Use the following command.

sudo apt-get update
sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

Now, add docker's GPG key

sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

Now give sufficient permission

sudo chmod a+r /etc/apt/keyrings/docker.gpg

In order to set up the repository, use the following command

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Now for installing Docker use the following command, which will install the latest docker.

sudo apt-get update & sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

Install Docker using .deb package:

If we might have a problem with installing the docker with the above or wants to install a specific version of the docker then using .deb package is a good solution.

Download the desired version of .deb from here

In order to test the ubuntu version use the following command

lsb_release -a

we can get the output as below

No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.3 LTS
Release:	20.04
Codename:	focal

Here, the codename is focal so We chose the same as above. Then browse to pool/stable/, choose amd64, armhf, arm64, or s390x, and download the .deb file

In order to test the CPU available use the following command

lscpu

Go to the download folder and execute the deb package using the following command

sudo dpkg -i docker-ce-cli_18.09.0_3-0_ubuntu-bionic_amd64.deb

Note: make sure to use your own version of the .deb package. Now start the docker

Now, we successfully install docker.

Check the Docker Version:

docker --version

Uninstall Docker:

Uninstall docker, CLI, Containerd, and Docker Compose packages using the following command

sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-compose-plugin

Now, delete all images, containers, and volumes

sudo rm -rf /var/lib/docker
 sudo rm -rf /var/lib/containerd

Share: