Create Docker Container for MSSQL on Mac


As the first step we need to install Docker Mac and make sure you have Rosetta get installed, in case of using Mac with M1 or M2. These Models come with Apple Silicon. Some of the older apps come with Intel chip support, Rosetta will help you the migrate to Apple Silicon.

Docker Compose

Using the Docker-Compose we can containerise MSSQL. Here is the working Docker-Compose file.

Create a Folder called MSSQL and add Docker-Compose.yml file with following contents

version: '3.9'

services:
  mssql-azur-edge:
    image: mcr.microsoft.com/azure-sql-edge 
    platform: linux/arm64
    ports:
      - 1433:1433
    volumes:
      - ~/apps/mssql/data:/var/lib/mssqlql/data
    environment:
      - ACCEPT_EULA=Y
      - SA_PASSWORD=mssql1Ipw

Since I’am using the Mac Min M2, which is an arm device, should specify in the platform key. Port key expose the internal port to external. Volume indicate the storage location which is optional.

In the environment key we can pass the Password for SQL Server etc.

Now . Run the Docker-compose up -d. for running the Container. If there is any problem , run this command for the log docker-compose logs

You are ready to use the sever. You can also use the Mac IP and exposed port in SQL Management studio or in a connection string as (source)

 Mac IP, 1433

Create a docker droplet in DigitalOcean

How to setup docker container on digital ocean cloud


Droplets allow us to create virtual machines for computing, containerizing deployment, hosting WordPress etc.

To use docker in our droplet, have to use the Marketplace tab and choose wisely.

Please choose Docker on Ubuntu for containerized deployment.

The cost for DigitalOcean Droplets starts with $5 monthly.

Droplet control panel shows your droplets, you can manage the VM here.

Note that turn off droplet will not stop the billing, destroy the droplet instead.

Don’t have a DO Account yet ?, Use this $100 and get started ?

DigitalOcean Referral Badge

How to Containerize Golang app with Docker

How to containerize Golang app using Docker


To containerize a Golang app is similar to any other project. We need to use the base image for golandg and build the app.

Install Docker desktop , if you are on windows and create an account first. Then in the project create Dockerfile ( no extension required) with following command.

Save the file in root of the project

FROM  golang:1.18beta2-bullseye
RUN mkdir /app
ADD . /app
WORKDIR /app
RUN go build -o main .
CMD ["/app/main"]

Building the Docker Image

Go to the terminal and CD into the project folder and build the image. Docker image can be used to run different process.

docker build -t my-go-app . 

try to list image using docker images command.

Using the image

To use the image we created withrun command.

docker run -d -p 8080:8080 --name test1 my-go-app

The above command will run the image in detached mode, leaving console reedy for another execution.

It also exposed to port internal 8080:8080. Go to the browser and try localhost:8080 and it should have working.

Stopping, Starting and removing containers

Using docker stop <container-name/id>. Once it stopped can delete using docker rm container-name/id command.

Need to start again ? use the docker start command.

Wanna know running processes/ containers ? Try docker ps.

How to create a strapi project with Docker on Windows

How to create a strapi project with Docker in Windows


Starpi is new gen CMS for Node based projects, and it help us to build and manage content using customizable Admin UI.

Docker : When start using different technologies and database, Docker can make dev work easier. Developer usually need to work with different databases,frameworks, languages etc, which require super awesome computer.

Docker container help us to run development environment within a disposable,light weight container, it can include, Mysql, Mongo, Strapi and more etct .. Each container working based on Docker Images. You can explore more about Docker Images @ Docker Hub

How to start

First we need Docker for desktop get installed in Windows machine and then we need to use the Docker image to create strapi project. You need a Linux Subsystem get installed on Windows for proper working of Docker.

On the terminal please issue the following command create a project at the drive E named starpiProject.

docker run -it -p 1337:1337 -v E:\starpiProject:/srv/app strapi/strapi

This will run a docker container with interactive terminal mode (-it) and use local storage or volume which will create a strapi project starpiProject (on drive e) folder and run at the port of localhost:1337.

You can visit the the local host in a web brower which welcome you with user signup form.

Run the existing Project ?

The same command can be work for us and in case of non existed project, new one will be created.

docker run -it -p 1337:1337 -v E:\starpiProject:/srv/app strapi/strapi

Have a look at these docker posts

Docker-compose for projects

How use docker-compose to run MySQL database base for development


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

How to build Node-Express project Docker Image using Node base image


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

How to build Node-Express project Docker Image.


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

How to stop all containers 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

Howto to remove all containers at once in docker

How to remove all containers 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