Showing posts with label helloWorld. Show all posts
Showing posts with label helloWorld. Show all posts

Oct 2, 2022

Start Docker with Multipass

Multipass is a great tool for working with containers. 

Minikube workflow is another great example of a built-in tool for container development. And Microk8s runs on top of Multipass cross-platform and is for pocket-sized Kubernetes.

Docker Workflow in Multipass

An extra tool in Docker workflow is Portainer. In fact, each VM instance created with the Docker workflow comes with a Portainer container already running in Docker. Once that instance is launched, you’re already up and running with a convenient GUI interface (at port 9000) for launching and managing your containers.

multipass launch docker -n <instance-name>

multipass launch docker -n dk

multipass info dk

To access the docker command interface:

multipass exec dk docker

To create alias for docker:

multipass alias <instance>:<command> <alias-cmd>

multipass alias dk:docker dkr 

To run the hello-world container:

dkr run hello-world 

multipass dkr run hello-world

multipass dkr version

multipass dkr version

To access the portainer with browser, open the URL at http://dk_ip_addr:9000

 

May 18, 2022

Docker HelloWorld_2

Continue from the hello_world_1, here comes another notes on running multiple containers with docker compose.

With Docker compose, we can configure and start multiple containers with a single yaml file. This is helpful for a technology stack with multiple technologies.

As an example, say that you are working on a project that uses a MySQL database, Python for AI/ML, NodeJS for real-time processing, and .NET for serving API’s. Docker makes this easier with the help of compose.

docker compose is a yaml file in which we can configure different types of services. Then with a single command all containers will be built and fired up.

There are 3 main steps involved in using compose:    

  • Generate a Dockerfile for each project.    
  • Setup services in the docker-compose.yml file.    
  • Fire up the containers.

Here is the full copy of docker-compose.yml.

docker-compose.yml:

version: '3.4'
services:
  super-app-db:
    image: mysql:8.0.28
    environment:
      MYSQL_DATABASE: 'super-app'
      MYSQL_ROOT_PASSWORD: 'password'
    ports:
      - '3306:3306'
    expose:
      - '3306'
  super-app-node:
    build: ./node
    ports:
      - "3000:3000"
  super-app-dotnet:
    build: ./dotnet
    ports:
    - "8080:80"
  super-app-python:
    build: ./python
  super-app-php:
    build: ./php
    ports:
    - "8000:80"

Then, we need to:

  • Configure MySQL
  • Configure NodeJS
  • Configure .NET 
  • Configure Python
  • Configure PHP

 

Links:

May 17, 2022

Docker HelloWorld_1

Containers are the building blocks of docker. Here's the note will go through various commands that will help manipulate and create containers, to give better understanding of how docker works.

First, create 3 files: Dockerfile, package.json, server.js

Dockerfile:

FROM node:17-slim
WORKDIR /app
COPY . .
RUN npm install
CMD ["node", "server.js"]
EXPOSE 3000

package.json:

{
    "name": "yay-docker",
    "dependencies": {
        "express": "^4.17.1"
    }
}

server.js:

const server = require("express")();
server.listen(8080, async () => { });
server.get("/nodejs", async (_, response) => {
  console.log('Request Received for nodejs');
  response.json({ "yay": "docker" });
});


Create an image and name it "simple_nodejs" from current folder. It will start multiple layers for downloading the node:17-slim image. Once done it will run npm install to install dependencies like express from your package.json file.

docker build -t simple_nodejs .

Run the image as container named "simple_nodejs" at port 3000 (external) while the node app running at port 8080 (internal).

docker run -p 3000:8080 -d simple_nodejs 

Now, we can test the container by browsing to http://localhost:3000/ 

List running containers

docker ps -a

Prints container logs

docker logs <container-id>

Access the container

docker exec -it <container-id> /bin/sh 

Start, stop, and remove container:

docker start <container-id>

docker stop <container-id>

docker rm <container-id>

 

Links: