Challenge to learn Docker
High-level: Using automation we want to spin up an environment which will allow us to connect to a web server on port 80 or 8080 and serve a bit of simple HTML content from a data storage source. You will be required to write a small application in the language/framework of your choice to connect to the database, query it, and return the result to the user.
· Developed within a git repository with frequent commits
· Automated way to spin up/down single machine environment (vagrant, docker compose, minikube etc)
· OS installation/configuration (Windows or Linux, any versions)
· Configuration management (Chef/Puppet/Ansible, Dockerfile or kube deployment files) to install and configure applications
· Installation of a web tier and data tier (your choice, e.g. NGINX/Apache/IIS, MySQL/PostgreSQL/Redis/etc)
· Running a simple web application to query and return data
- Please install docker. https://hub.docker.com/editions/community/docker-ce-desktop-mac
- Clone the github repo git clone https://github.com/andi23/DockerTest.git
- Open terminal and cd to DockerTest/test/
- run command " docker-compose up "
- open a browser and hit " http://localhost:8080/ "
- Please install docker. https://hub.docker.com/editions/community/docker-ce-desktop-mac
- Clone the github repo git clone https://github.com/andi23/DockerTest.git
- Open terminal and cd to DockerTest/test/
- run command " ./services.sh " -if there is an error of "Permission denied" -> please run the command " chmod +x services.sh " . This is to basically give permission to run the services.sh file.
- Open a browser and hit " http://localhost:8080/ "
- I want to understand the requirements and the technology stack involved
- Read and implement the Docker tutorial in the official page https://docs.docker.com/get-started/part5/
- I need to have a web app. I had some experience using Flask. Flask with containers?
- I need a database. I had some experience using MySQL. MySQL with containers? https://developer.ibm.com/tutorials/docker-dev-db/
- Now that I have done tutorials and have a better understanding, what is the tech stack do I want to use ?
- Automated way to spin up/down single machine environment -> Docker
- Configuration management -> Dockerfile
- Web tier -> Flask
- Data tier -> MySQL
- I want to start with a containerised mySQL data tier and implement it.
- After having done the containerised data tier, I want to create the web tier using Flask deployed in a container.
- After having made connected Flask web tier and the data tier, is there anything I can do ? In a separate git branch "services", I made the app load balanced by scaling the services.
- Begin with making the data tier. 2 ways to do this. Either from an existing SQL file with the database, table, thousands of rows of data like the ibm tut and then simply use docker-compose. Or simply create a new database, define the schema, add some data to the table.
- Having created the sql model, I used the docker-compose.yml file with just the sql model and then connected to it using
mysql -P 3306 --protocol=tcp -u root -p. SQL queries can then be used to verify the data present. - Now that the container for data model is working well, I started to build the web app using Flask. The web app will be able to simply display the data in the mySQL database and is in a container.
- The containers are able to connect from the docker-compose.yml in which the Flask app is linked to the databse.
- Simply test out docker-compose up and then go to the link at http://0.0.0.0:8080/ to check results.
- No experience in using containers so had to study for that.
- Following the tutorial and absorbing the knowledge instead of blindly following was a fun challenge. The ibm tut and docker tut were very helpful.
- Stop the containers -> docker container stop $(docker container ls -a -q)
- Remove the containers -> docker container rm $(docker container ls -a -q)
- Remove the images -> docker image rm $(docker image ls -a -q)
- Verify
-- Docker container: docker container ls
-- Docker image: docker image ls
- docker stack rm flaskMolly
- docker swarm leave --force
- docker swarm ls -> "This node is not a swarm manager ...."
