I posted an article with the title [Efficient Web system development using containers and Git], but after that I also tried using docker-compose
I tried it, so I will write down the contents at that time as a memo.
[Docker installation environment] ・ Ubuntu 20.04 LTS (on GCP) ・ Docker 19.03.13 ・ Docker-compose 1.25.0
[Container environment] ・ Image Ubuntu: 20.04 -Apache 2.4.41 * Since the version is not specified, the latest version at the time of installation
In the following flow, try starting / stopping the Web service using docker-compose
.
docker-compose
** Create a VM instance on GCP **
** Package management tool update **
$ sudo apt update
** Install git **
python
$ sudo apt install -y git
** Install docker **
** Install docker-compose **
python
$ sudo apt install -y docker-compose
Check if the installation is successful
python
$ ddocker-compose --version
docker-compose version 1.25.0, build unknown
Do the following on Github:
** ■ Create a repository for Public **
** ■ Create an "App" folder directly under the created repository **
** ■ Create index.html in the "App" folder **
** ■ Cut a development branch **
main (for production)
and dev (for development)
.** Prepare files with the following directory structure **
./docker-compose.yml
./Dockerfile
./site_config/
- demo_site.conf
./mount/
- main/
--Clone the main
branch on Github
- dev/
--Clone the dev
branch on Github
Directory creation
#################################################
#Directory for storing site config configuration files#
#################################################
$ sudo mkdir ./site_config
################################
#Create a directory for mounting#
################################
$ sudo mkdir ./mount
#Source code storage location
$ sudo mkdir ./mount/main
$ sudo mkdir ./mount/dev
Clone the source on Github
$ sudo git clone --depth 1 -b main https://github.com/Smiler5617/test_websys.git ./mount/main
$ sudo git clone --depth 1 -b dev https://github.com/Smiler5617/test_websys.git ./mount/dev
** Create each file as below **
demo_site.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/App/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Dockerfile
#Get base image
FROM ubuntu:20.04
#Installation of required packages
RUN apt update
RUN apt install -y tzdata
RUN apt install -y apache2
#Loading site settings
COPY ./site_config/demo_site.conf /etc/apache2/sites-available/
RUN a2dissite 000-default
RUN a2ensite demo_site
#Create a directory for mounting
RUN mkdir /var/www/html/App
#Port open
EXPOSE 80
CMD ["apachectl", "-D", "FOREGROUND"]
docker-compose.yml
version: '3.7'
services:
web_main:
build:
context: .
dockerfile: Dockerfile
volumes:
- ./mount/main/App:/var/www/html/App
ports:
- 8080:80
web_dev:
build:
context: .
dockerfile: Dockerfile
volumes:
- ./mount/dev/App:/var/www/html/App
ports:
- 8081:80
docker-compose
** Launch all services **
python
$ docker-compose up
If you can access the following environment, you can start it for the time being.
http: // [VM external IP (global IP address)]: 8080 /
http: // [VM external IP (global IP address)]: 8081 /
** Start / Stop **
Ctrl + C
** Run in background **
python
$ docker-compose start
Starting web_main ... done
Starting web_dev ... done
$ Docker-compose up -d
is OK, but if you want to check the log, start
is good.Stop
python
$ docker-compose stop
Stopping [Google account name]_web_dev_1 ...
Stopping [Google account name]_web_main_1 ...
** You can also specify to start or stop the service **
python
$ docker-compose start web_main
Starting web_main ... done
$ docker-compose stop web_main
Stopping [Google account name]_web_main_1 ...
** Service Suspension & Removal **
python
$ docker-compose down
start
or restart
.Recommended Posts