Table of contents
Postgres
docker pull postgres:9.6.14
You can change the Postgres password by changing the
_POSTGRESS_PASSWORD_value from_hydrogen_to any preferred secured password
docker run --name <CONTAINER_NAME || postgres-9.6.14> -e POSTGRES_PASSWORD=hydrogen -p 5432:5432 -d -v $HOME/docker/volumes/postgres:/var/lib/postgresql postgres:9.6.14
PSQL Terminal
Use the following command to hop into the PSQL terminal session.
docker exec -ti <CONTAINER_NAME || postgres-9.6.14> psql -h localhost -U postgres
data-source in
respository/conf/identity/identity.xmlwith thePostgresJNDIconfiguration name
<!-- identity.xml -->
<JDBCPersistenceManager>
<DataSource>
<!-- Include a data source name (jndiConfigName) from the set of datasources defined in master-datasources.xml -->
<!-- <Name>jdbc/WSO2CarbonDB</Name> -->
<Name>jdbc/WSO2CarbonPostgresDB</Name>
</DataSource>
</JDBCPersistenceManager>
MySQL
docker pull mysql
Run Container
docker run --detach --name=jspmysql --env="MYSQL_ROOT_PASSWORD=jsppassword" --publish 6603:3306 mysql
Exposing MySQL Container to Host
Expose the
MySQLcontainer to the outside world by mapping the container’sMySQLport to the host machine port using thepublishflag.
Now, we can connect to theMySQL
container through port 6703
Notice, the IP address comes from docker machine. For my docker machine, it is 192.168.99.100.
docker rm -f jspmysql
docker run --detach --name=jspmysql --env="MYSQL_ROOT_PASSWORD=jsppassword" --publish 6703:3306 mysql
Creating MySQL Image
docker run --detach --name=jspmysql --env="MYSQL_ROOT_PASSWORD=jsppassword" --publish 6603:3306 mysql
What is this command doing?
Create a
MySQLcontainer namedjspmysqlSet environment variable ` MYSQL_ROOT_PASSWORD
tojsppassword`Expose
3306and map to6603for an outside world to connect to thisMySQLdatabaseIn addition, we manually created database
jsptutorialand tableProduct
mysqladmin -u root -p create jsptutorial
mysql -u root -p jsptutorial < jsp_backup.sql
Creating MySQL Image with Dockerfile
Creating Docker File
Create one file named Dockerfile in any directory on local machine.
cd ~/Johnny
mkdir DockerMySQL
cd DockerMySQL
vim Dockerfile
Create MySQL Image for JSP Tutorial Application
FROM mysql
MAINTAINER csgeek@mail.com
ENV MYSQL_ROOT_PASSWORD jsppassword
ADD jsp_backup.sql /docker-entrypoint-initdb.d
EXPOSE 3306
The first line is a comment. You can add comments to the Docker File with the help of the # command
The FROM keyword tells which base image you want to use. In our example, we are creating an image from the mysql image.
The next command is the person who is going to maintain this image.
The ENV command is used to set environment variable. We set MYSQL_ROOT_PASSWORD to jsppassword for MySQL database.
The ADD command copies the database backup file to /docker-entrypoint-initdb.d directory in the Docker container.
The docker-entrypoint.sh file will run any files in this directory ending with“.sql” against the MySQL database.
In our example, we have only one sql script file jsp_backup.sql.
The EXPOSE command exposes port 3306 of the image.
Creating Image with Dockerfile
Open Docker terminal, navigate to the folder where the Dockerfile and MySQL backup file locates. Run the following command.
docker build -t jspmysql:0.1 .