Docker-compose for projects


In the past docker posts we used docker run command to run containers using docker image and also the Dockerfile to create project image.

Sometimes we need to use/run a database in container during development, in such cases docker-compose came into light.

The Docker-Compose file

Docker-compose is a file at the root of your project, which has no extension and carry some special script. In our example we are configuring MySQL database.

version: '3.1'
services:
  db: 
    image: mysql
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment: 
      MYSQL_ROOT_PASSWORD: example
      MYSQL_USER: development
      MYSQL_PASSWORD: development
      MYSQL_DATABASE: blog
    ports: 
      - 127.0.0.1:3306:3306

Up and Down

To start the docker-compose use the up command from the project root

docker-compose up -d

The down command used to remove and stop for stopping the container .

Checking the docker-compose containers

For listing the containers we can use

docker-compose ps

Accessing MySQL CLI

Login into the database and create some database ( as root)

docker exec -i some-id sh -c "exec -uroot -p password"

You can also use -u username for login as normal user and can execute basic sql operations such create database, tables and CURD operations on objects etc. Note that the database uses the default port of MySQL

We can stop running a container at any time using docker stop <id/name> and resume with docker start <id/name>

Following Docker Post may deserve a good read

Create a docker image of Node-Express API – Part II


In this post which is the continuation of Node-API Docker Image ( the Links are at the end of the post), create and run container using the image we build.

Lets check the existence of the image in docker using

docker image

Create the container

To build a container to run the API we need only the Image , all the depending Image will be automatically download by Docker.

docker run --name customer -d -p 3000:3000 user-api:latest

The above command will run, customer API in detached mode on port 3000.

Stop and Resume the container

We can stop running a container at any time using docker stop <id/name> and resume with docker start <id/name>

Following Docker Post may deserve a good read

Create a docker image of Node-Express API – Part I


In this post we are create Docker Image of a NodeExpress app which can be used to deploy and run the app. The image can be used to deploy multiple container as well. Following are the requirements for this tutorial

Requirements

  • NPM
  • Nodejs
  • VSCode/Atom

Node-Express API

Lets create a folder and create file index.js and paste the following API site content

const express = require('express')
const app=express()
require("dotenv").config();

app.get('/',(req,res)=>
  res.json([{name:'manoj',email:'codehat@outlook.com'
  },
  {name:'mariah',email:'codehat@outlook.com'
  }])
)
app.listen(process.env.PORT || 3000,()=>console.log(`Server running on port ${process.env.PORT}`))

Our API is a simple USER API which shows a list of users. Let’s setup the package.json file by issuing npm command and install dependencies

Howto to stop all containers at once in docker


Docker is a developer tool which help us to run applications in an isolated environment, where you can start a service, app,local host, MySQL, SQL server, mongodb etc.

Get the container id

To stop container we can use ids of container they, can be , many. First thing we need grab all the ids using the

docker pa -aq

Then use those ids as arguments to stop command as follows

docker stop $(docker ps -aq)

that’s it

Docker posts that may help you

Create portfolio app with nginx in 5 minute


nginx is a docker image where you can run a local website. I have post regarding Docker blow the post, in case you need them. We can nginx it to create a static site on localhost with Docker container.

Static/Dynamic web page

As the name indicates the content of our web app remain the same. Grab a beautiful bootstrap for quick start, I have on from https://startbootstrap.com/previews/stylish-portfolio

  • Download the complete code
  • Place them in a local folder (portfolio)
  • Access Powers-hell/CLI/Terminal

Docker Volume

Docker volume is allow us to host data from local system. In our case we want to copy the content of our portfolio web app to /usr/share/nginx/html (nginx folder) in the docker container.

volume can added to container using the -v or –volume label in a docuker run command. Without the :ro the data will be updated when ever a change made the source folder.

Can I dive into nginx folder ?

Yes you can explore the Linux shell using the following command with container ID/name

 docker exec -it 9a99a1ad28e1  bash
 cd /usr/share/nginx/html 
 ls  // see all the files

Let’s create and run the container

Read only
docker run --name myapp -v e:/portfolio:/usr/share/nginx/html:ro  -d -p 8080:80 nginx:latest
Dynamic
docker run --name myapp -v e:/portfolio:/usr/share/nginx/html  -d -p 8080:80 nginx:latest

:ro stands for read only, you can remove it and the data will change as you edit the content in the source folder, in a limited sense it can be dynamic.

Go to the browser and try http:///localhost:8080

You can use the id/name to stop/start/remove the container.

docker stop 6ec62466d248  //stop container with id
docker start 6ec62466d248  //start container with id
docker rm    6ec62466d248  //remove the container with id

Other Docker posts you may interested in

Howto to remove all containers at once in docker


Docker is a developer tool which help us to run applications in an isolated environment, where you can start a service, app,local host, MySQL, SQL server, mongodb etc.

Get the container id

To remove container we can use rm command with ids of container. First thing we need grab all the ids using the

docker pa -aq

Then use those ids as arguments to stop command as follows

docker rm $(docker ps -aq)

that’s it

Docker posts that may help you

Start a nginx app container in Docker


nginx is a docker image where you can run a local website. I have post regarding Docker, in case you need them.

What is a container ?

A container is consisting of copy of Docker Image and an app. You can create as many containers and start/stop/remove them and link them together. Lets create a nginx server.

Run the following code in case don’t have the nginx docker image in your computer.

docker pull nginx //download the image
docker images //list images

Crate a container

Let’s create container and run a sample web app

docker run --name myapp -t latest -d -p 8080:80 nginx:latest

This will run an nginx app on the local host port 8080 which is mapped to 80. To list all containers you can use either on of the command

Go to the browser and try http:///localhost:8080

Other commands

docker ps // list of containers
docker ps -a //stopped containers
docker container ls // list of containers

You can use the id/name to stop/start/remove the container.

docker stop 6ec62466d248  //stop container with id
docker start 6ec62466d248  //start container with id
docker rm    6ec62466d248  //remove the container with id

Wanna remove an image ? use docker rmi <image-id>

Other Docker posts you may interested in

Howto download images in Docker


Docker is a developer tool which help us to run applications in an isolated environment, where you can start a service, app,local host, MySQL, SQL server, mongodb etc and they can can communicate each.

Images

Images are used to create container which are used to run apps and services. You can find image of Redis, Mongo, MySQL, Ubuntu and everything needed for a develop and test app @ https://hub.docker.com/

Find the image you want and copy the docker pull code.

Open the command prompt. Before start downloading I will show you how you can view a list of Images you had

docker images

This will list all the docker images in your computer. Lets download nginx web server

docker pull nginx
docker images

Docker : A tool for developers


Think of a ship dock, which full of containers, thousands of them. Each of them contain different things, in a fantasy term different world. Docker is something like that.

It is a developer tool which help us to run applications in an isolated environment, where you can start a service, app,local host, MySQL, SQL server, mongodb etc and some of them can communicate each. It’s like a VM , isn’t it?

You need not to install many database on system any more , use a docker container and still can access with workbench.

How to install Flutter on Ubuntu Linux


Lets Install Flutter for Ubuntu Linux development. As a open source project, we can install the flutter SDK from GitHub.

The prerequisites

In order to clone the repository we have to use git . In case your SUSE doesn’t know what it is, let’s install it with snap . Also recommend to have Visual Code /Atom for editing the code.

The following post may help you to install VS Code on Ubuntu

Install the git

sudo snap install git

Clone the repo

Get the latest stable version from GitHub repository or alternatively can download from flutter site

git clone https://github.com/flutter/flutter.git -b stable --depth 1

Use the -b option to clone the stable version

Setup the path variable

You also need to set the path variable using the shell command as follows.

export PATH="$PATH:pwd/flutter/bin"

Call the Doctor

run Flutter doctor command to inspect status of your Flutter SDK

Flutter Doctor

Android IOS development

For Android you have to install the Android Studio for development tool support which can be download from official website.

For official documentation visit flutter.dev