Working with docker images

Installing Docker

Reference from :  https://docs.docker.com/engine/install/ubuntu/

sudo apt-get remove docker docker-engine docker.io containerd runc

sudo apt-get update

sudo apt-get install \

    apt-transport-https \

    ca-certificates \

    curl \

    gnupg-agent \

    software-properties-common

Add Docker’s official GPG key:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -


Verify fingerprint

sudo apt-key fingerprint 0EBFCD88


Add repo

sudo add-apt-repository \

   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \

   $(lsb_release -cs) \

   stable"

   

Update repo and Install docker engine

sudo apt-get update

sudo apt-get install docker-ce docker-ce-cli containerd.io


Check docker is running

ps ax|grep docker


Test HelloWorld package

sudo docker run hello-world


Install docker on windows

after instllation, restar tthe PC


If the Linux kernel is not updated, install it manually

Download from https://docs.microsoft.com/en-us/windows/wsl/wsl2-kernel

go to windows shell

docker

docker run hello-world


Run official docker image

goto hub.docker.com from the browser

find odoo

open Linux terminal

Install postgres using docker image

docker run -d -e POSTGRES_USER=odoo -e POSTGRES_PASSWORD=odoo -e POSTGRES_DB=postgres --name db postgres:12


Start odoo instance

docker run -p 8069:8069 --name odoo --link db:db -t odoo


Now go to your <ipaddress>:8069 and you can be able to see it working

https://github.com/odoo/docker


Working with Docker File

Go to terminal

mkdir customer_docker

git clone https://github.com/odoo/docker.git

nano /custom_docker/docker/13.0#

Dockerfile  entrypoint.sh  odoo.conf  wait-for-psql.py


Make it executable

chmod +x entrypoint.sh


Craeate new account at hub.docker.com

Create new repo


Build custom image

nano /custom_docker/docker/13.0

nano Dockerfile

Change maintainer info


By default, it will look for Dockerfile and if you have different filename, put -f tag

docker build -t thetnswe/odoo_docker01:1.0 .


after that, view for local docker images

docker images 


List the docker addresses

docker ps -a 


Start Postgres intance

docker start db

docker ps


Installing postgres from docker if it hasn't exist yet

db use the instance name of postgres

docker run .. postgres:12

docker run -p 8069:8069 --link db:db -t thetnswe/odoo_docker01:1.0


-y means all yes


//Now explain all about the the Dockerfile basically, it run all the require commands that odoo is needed to run


Install install additional python package to our customer docker image

RUN pip3 install simplejson

add python3-wheel \ which is required by pip3


Now build the package

docker build -t thetnswe/odoo_docker01:1.1 .


Build Run and push the image

/tmp/data: - volume of the host computer will be created automatically if it's not existed yet

/var/lib/odo - volume of the container that we want to share to the host computer

make sure that db instance is already running

docker run -v /tmp/data:/var/lib/odoo --link db:db thetnswe/odoo_docker01:1.0


Run with addons (-v volume)

docker run -v /tmp/data:/var/lib/odoo -v /tmp/addons:/mnt/exra-addons --link db:db thetnswe/odoo_docker01:1.0

so with this, anything that we add on /tmp/addons will be available also in container/mnt/extra-addons


Running in the background (-d)

docker ps

docker run -d -v /tmp/data:/var/lib/odoo -v /tmp/addons:/mnt/exra-addons --link db:db thetnswe/odoo_docker01:1.0

docker ps 

docker logs festive_mendeleev (NAMES field the the ubuntu is generated)


See log file in real-time (-f)

docker logs -f festive_mendeleev


Enter to the container shell

docker exec -it festive_mendeleev bash

ls -l to see all the file listed


//Entering as root user

docker exec -it -u root festive_mendeleev bash


Run with custom config on host

/etc/odoo - odoo container config file

/tmp/config - external config file to override

docker run -d -v /tmp/data:/var/lib/odoo -v /tmp/addons:/mnt/exra-addons -v /tmp/config:/etc/odoo --link db:db thetnswe/odoo_docker01:1.0

cd /tmp/config

docker ps

docker logs <NAME>


Stopping the container

docker stop <NAME>


Copy the default config file to mounted one

nano custom_docker/docker/13.0

cp odoo.conf /tmp/config


Stop, Start, Restart container

docker ps

docker stop <NAME>


List available containers (Start)

docker ps -a 

docker start <NAME>

Restart docker restart <NAME>


Run with inline arguments

docker run -d -v /tmp/data:/var/lib/odoo -v /tmp/addons:/mnt/exra-addons -v /tmp/config:/etc/odoo --link db:db thetnswe/odoo_docker01:1.0 -- --log-level=debug 


Pushing docker image

docker login

docker images

docker push <image_name>:<version>


Remove containers that're run before

docker ps -a 

docker rm <NAMES in space seperated>


Environment variables

can look at entrypoint.sh file

run with --scaffold option to check psql container in local

docker run -e HOST=<ipaddress> -e PORT=5432 -e USER=<db_username> -e PASSWORD=<db_password>

docker run -e HOST=128.199.210.129 -e PORT=5432 -e USER=odoo thetnswe/odoo_docker01:1.0


Docker composer

Install docker compose

Reference from : https://docs.docker.com/compose/install/


sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose


cd /custom_docker/docker/13.0#

nano docker-compose docker-composer.yml file and paste the following codes


Docker compose examples

https://hub.docker.com/_/odoo

version: '2'

services:

  web:

    image: odoo:13.0

    depends_on:

      - db

    ports:

      - "8069:8069"

  db:

    image: postgres:10

    environment:

      - POSTGRES_DB=postgres

      - POSTGRES_PASSWORD=odoo

      - POSTGRES_USER=odoo

  

put -f if there's no docker-composer.yml file is provided and want to point to specific file

then docker-compose up -d to start in background


Pull the latest images

docker-compose pull to 


Mounting local addons

Add volumes information in docker-compose.yml file

docker-compose up


web_1  | grep: /etc/odoo/odoo.conf: No such file or directory

cp odoo.conf config/


nano /custom_docker/docker/13

mkdir addons

cd addons

wget <Addon URL>

then unzip addons

docker-compose up


Turn on the debug mode

Now go to the website browser <ip_address>:<port>

?debug=1 to the url


Embedding custom addons

mkdir addon_sources

unzip <filename>

rm <filename>

COPY ./addon_sources /opt/addons just before USER odoo

nano odoo.conf 

add ,/opt/addons to the addons path list

Then build a new version

docker build -t thetnswe/odoo_docker01:1.2 .

docker images

nano config/odoo.conf 

Add add ,/opt/addons to the addons path list


nano docker-compose.yml

Change image name to thetnswe/odoo_docker01:1.2

docker up

docker up -d 


Go inside the docker image folder

docker exec -it 130_web_1 bash








Comments

Popular posts from this blog

Setting up Odoo 13 on Digital Ocean's ubuntu

Install Odoo13 on ubuntu