How to stop docker under Linux

 I can stop docker after put two commend. 

> sudo systemctl stop docker

[sudo] password for mare: 

Warning: Stopping docker.service, but it can still be activated by:

  docker.socket

> sudo systemctl stop docker.socket


I hope it's helpful to you.

Thank you.

🙇🏻‍♂️

print docker memory usage size and image size on command line

Print docker container men usage 

.

docker stats --no-stream --format "table {{.Container}}\t{{.MemUsage}}"
CONTAINER MEM USAGE / LIMIT
df1db3352f5c 62.85MiB / 7.581GiB
e225c0866cef 778.8MiB / 7.581GiB
8e40a961b59d 1.121GiB / 7.581GiB
f66e33681593 173MiB / 7.581GiB

..

Print image size

.

docker ps --format '{{.Image}}' | uniq | xargs -I {} docker image ls --format "table {{.Repository}}\t{{.Size}}" {}
REPOSITORY SIZE
5978.com/fast-api 643MB
REPOSITORY SIZE
5978.com/recognition 2.52GB
REPOSITORY SIZE
5978.com/detector 746MB

..


.

All together 

#!/bin/bash
echo "Memory Usage of Running Containers:"
docker stats --no-stream --format "table {{.Container}}\t{{.MemUsage}}"
echo ""

echo "Image Size of Running Containers:"
docker ps --format '{{.Image}}' | uniq | xargs -I {} docker image ls --format "table {{.Repository}}\t{{.Size}}" {}

..


Thank you.

www.marearts.com

🙇🏻‍♂️

docker Multi-Architecture Builds



Multi-Architecture Builds

Docker's Buildx extension allows you to build multi-architecture images. You can specify multiple target architectures and create a single image that works on both. Here's a simplified example:

This will create an image that can run on both Intel (amd64) and ARM (arm64) based systems.


# Initialize Buildx (one-time operation)
docker buildx create --use

# Build multi-architecture image
docker buildx build --platform linux/amd64,linux/arm64 -t your-image-name:tag .

Useful Docker Commands: List, Stop, Remove, Logs, Build, Push, Pull, and Delete Images

 

refer to cmd


.

# List all running containers
docker ps

# List all containers, including stopped ones
docker ps -a

# Stop a running container
docker stop <container-id>

# Remove a stopped container
docker rm <container-id>

# View logs from a container
docker logs <container-id>

# Execute a command in a running container
docker exec <container-id> <command>

# Build an image from a Dockerfile
docker build -t <image-name> <path-to-dockerfile>

# Push an image to a Docker registry
docker push <registry>/<image-name>

# Pull an image from a Docker registry
docker pull <registry>/<image-name>

# Remove all Docker images using prune option
docker image prune -a -f

..


Thank you.

🙇🏻‍♂️

www.marearts.com

The command '/bin/sh -c apt-get install -y curl' returned a non-zero code: 100 while docker build

 

ADD this 2 cmd in docker file


RUN apt-get -y upgrade
RUN apt-get -y update

Thank you!

'ascii' codec can't encode character '\uc790' in docker

 put this line in Dockerfile

ENV LANG C.UTF-8

^^


Retrive docker container IP address



replace 'container_name_or_id' -> 'you id or container name'

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id

Thank you.

Docker container stop by image name

 Stop docker container by image name:

imagename='mydockerimage'
docker stop $(docker ps | awk '{split($2,image,":"); print $1, image[1]}' | awk -v image=$imagename '$2 == image {print $1}')

Stop docker container by image name and tag:

imagename='mydockerimage:latest'
docker stop $(docker ps | awk -v image=$imagename '$2 == image {print $1}')

docker swarm simple command

*install virtualbox

-+-

#install virtualbox on terminal
#osx
brew install virtualbox
#linux
sudo apt install virtualbox

-+-

 

* install docker-machine

...

#osx
curl -L https://github.com/docker/machine/releases/download/v0.16.2/docker-machine-`uname -s`-`uname -m` >/usr/local/bin/docker-machine && chmod +x /usr/local/bin/docker-machine
#linux
curl -L https://github.com/docker/machine/releases/download/v0.16.2/docker-machine-`uname -s`-`uname -m` >/tmp/docker-machine && chmod +x /tmp/docker-machine && sudo cp /tmp/docker-machine /usr/local/bin/docker-machine

...


*docker-machine

...

#docker-machine basic cmd
docker-machine ls
docker-machine rm name
docker-machine kill name
docker-machine create name

...



unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /var/lib/snapd/void/Dockerfile: no such file or directory

 

if you install docker using snap, it can be happen.

so remove docker from snap installation

> sudo snap remove docker


And install docker again using apt

> sudo apt update
> sudo apt upgrade
> sudo apt install docker.io
> sudo systemctl enable --now docker


Thank you.
www.marearts.com


make python package zip for lambda layer using docker

 Here is good reference for this subject:

https://aws.amazon.com/premiumsupport/knowledge-center/lambda-layer-simulated-docker/

https://dev.to/matthewvielkind/creating-python-aws-lambda-layers-with-docker-4376



If we use docker then it's very simple.

Let's go through step by step


1. make Main folder & python library folder

ex) In this tutorial, we suppose to need flask package

mkdir flask-layer
cd flask-layer
mkdir -pv python/lib/python3.6/site-packages
or
mkdir -pv python/lib/python3.8/site-packages


2. make requirements.txt and put packages to install by pip

flask==1.1.1


So folder structure looks like this:

├── requirements.txt └── python/ └── lib/ ├── python3.6/ │ └── site-packages/ └── python3.8/ └── site-packages/


3. Run docker to install packages

note, change python version properly

docker run -v "$PWD":/var/task "public.ecr.aws/sam/build-python3.6" /bin/sh -c "pip install -r requirements.txt -t python/lib/python3.6/site-packages/; exit"

 

4. compress package to zip

zip -r yourpack.zip python > /dev/null


5. use zip file for your lambda

That's it all.


Thank you.

www.marearts.com

🙇🏻‍♂️


docker stop and remove all container, remove all images

 




stop all containers:
docker kill $(docker ps -q)

remove all containers
docker rm $(docker ps -a -q)

remove all docker images
docker rmi $(docker images -q)

Run amazon-linux 2 on local computer using Docker

 

I suppose you already installed docker.


1. pull Amazon Linux image

> docker pull amazonlinux

* https://hub.docker.com/_/amazonlinux


2. run container and enter the os

> docker run -it amazonlinux /bin/bash


3. check version

bash-4.2# > cat /etc/os-release
NAME="Amazon Linux"
VERSION="2"
ID="amzn"
ID_LIKE="centos rhel fedora"
VERSION_ID="2"
PRETTY_NAME="Amazon Linux 2"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
HOME_URL="https://amazonlinux.com/"

or

bash-4.2# > cat /etc/system-release
Amazon Linux release 2 (Karoo)


Thank you.

🙇🏻‍♂️

use docker without sudo

1.Create the docker group.
> sudo groupadd docker

2.Add your user to the docker group.
> sudo usermod -aG docker $USER

3.Log out and log back in so that your group membership is re-evaluated.
> newgrp docker 

4.Verify that you can run docker commands without sudo.
>docker run hello-world

transfer local docker image to another machine


Transfer docker image A -> B
1. Make zip file on A 
docker save -o ./example.tar image_name

2. Transfer example.tar  A to B using scp, rsync, or in some way

3. Load image on B
docker load -i ./example.tar

install docker on ubuntu 18.04

Step 1: Update Software Repositories
sudo apt-get update

Step 2: Uninstall Old Versions of Docker
sudo apt-get remove docker docker-engine docker.io

Step 3: Install Docker
sudo apt install docker.io

Step 4: Start and Automate Docker
sudo systemctl start docker
sudo systemctl enable docker

Step 5 (Optional): Check Docker Version
docker --version

Install python 3.6 on AmazonLinux and make Docker image


Run Amazon Linux Container (and tunnelling)
> docker run -v $(pwd):/outputs --name lambdapack -d amazonlinux:latest tail -f /dev/null

Run container bash shell
> docker exec -i -t lambdapack /bin/bash
Install python 3.6
bash# yum -y update
bash# yum -y upgrade
bash# yum install -y \
 wget \
 gcc \
 gcc-c++ \
 findutils \
 zlib-devel \
 zip

bash# yum install -y yum-utils
bash# yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
bash# yum install -y python36.x86_64
bash# yum install -y python36-devel.x86_64
bash# curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
bash# python36 get-pip.py
bash# pip3 install virtualenv
bash# exit

Make docker Image
> docker commit lambdapack marearts/amazon_linux_py36:v1.0.0

Push Docker Image to Docker Hub
>docker login
..
>docker push marearts/amazon_linux_py36:v1.0.0


Done!
Take Care!




docker command summarise


stop all containers:
docker kill $(docker ps -q)

remove all containers
docker rm $(docker ps -a -q)

remove all docker images
docker rmi $(docker images -q)

access(enter) docker container
docker exec -it docker_container_name sh

Exit from docker container
>exit

Commit container and build image
docker commit container_name image_name
ex) docker commit lambdapack lambda_image
ex) docker commit lambdapack marearts/lambda_image:v1.0.0

Docker build
>docker build --tag hello:0.1 .
>docker build --tag marearts/hello:0.1 .

Docker run shell and tunnelling 
>docker run -v $(pwd):/outputs --name nickname -d docker_image tail -f /dev/null
ex)
>docker run -v $(pwd):/outputs --name lambdapackgen2 -d marearts/awspy:0.1 tail -f /dev/null

Docker run shell

> docker run -it marearts/amazon_linux_py36:v1.0.0 /bin/bash

Docker run sh file in container
>docker exec -i -t container_name /bin/bash /outputs/shfile.sh
ex)
>docker exec -i -t lambdapackgen2 /bin/bash /outputs/buildPack_py3.sh

Restart Docker container
>docker restart <container id or name>
ex)
docker restart 59



it will be updated..


summarise Azure function docker image deploy



*make python virtualenv
*activate python virtualenv !!
*install azure util cli
https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-function-linux-custom-image#run-the-build-command

make project (app)
func init DocApp100 --docker

change directory
cd DocApp100

new function
func new --name MyHttpTrigger --template "HttpTrigger"

build docker image
docker build --tag marearts/image:v1 .

make new resource group
az group create --name DocGroup --location westeurope

storage account
az storage account create --name docstorage100 --location westeurope --resource-group DocGroup --sku Standard_LRS

create linux service plan
az appservice plan create --name docserviceplan --resource-group DocGroup --sku B1 --is-linux

create app and deploy
az functionapp create --name docapp100 --storage-account docstorage100 --resource-group DocGroup --plan docserviceplan --deployment-container-image-name marearts/image:v1

Configuration the function app
storageConnectionString=$(az storage account show-connection-string --resource-group DocGroup --name docstorage100 --query connectionString --output tsv)
az functionapp config appsettings set --name docapp100 --resource-group DocGroup --settings AzureWebJobsDashboard=$storageConnectionString AzureWebJobsStorage=$storageConnectionString

Test
curl https://docapp100.azurewebsites.net/api/MyHttpTrigger?name=myname


E: Unable to locate package nvidia-docker

go to this page and run the properly command.

https://nvidia.github.io/nvidia-docker/