Update all odoo modules in a docker container - odoo

I am working on a Odoo Docker container. I tried to find the appropriate command to update all the modules through the command line there but in vain. What is the appropriate command to do so ? I've put docker restart container_name -u all but also in vain.
Thanks in advance !

If you are using the docker-compose up command to start your servers, then you need to add the following line to your docker-compose.yml file under the odoo service:
command: odoo -u all -d odoo-prod
Where odoo-prod is the name of your database. This overwrites the default command (which is just odoo without update) and tells docker to update all modules when the container restarts.
Alternatively, you can also run a separate container that performs the updates:
docker run -v [your volumes] odoo:10.0 odoo -u all -d odoo-prod
This also overwrites the command from the dockerfile with the command stated here that includes the update.

You should have an ENTRYPOINT or CMD in your Dockerfile that runs python odoo.py -u all, the -u all option is for Odoo not docker restart

Open your container console
docker exec -it odoo bash
Update your module using other port
/usr/bin/odoo -p 8070 -d mydb -u mymodule
If the database it's on another container
/usr/bin/odoo -p 8070 --db_host=172.17.0.2 --db_user=odoo --db_password=odoo -d mydb -u mymodule

Related

Docker entrypoint initdb PERMISSION DENIED

I am getting the following error when I run docker-compose up:
Thanks a lot for your help
I resolved this problem by adding this to the Dockerfile after it copies the scripts to docker-entrypoint-initdb.d
RUN chown -R mysql:mysql /docker-entrypoint-initdb.d/
Example Dockerfile:
FROM mysql:latest
ENV MYSQL_DATABASE NAME_DATABASE
ENV MYSQL_ROOT_PASSWORD ***********
COPY ./sql-scripts/ /docker-entrypoint-initdb.d/
RUN chown -R mysql:mysql /docker-entrypoint-initdb.d/
EXPOSE 3306
CMD ["mysqld", "--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci"]
The next step is to build the image:
docker build -t image-db:latest .
The next step is to create the container
docker run -d -p 3306:3306 --name container-db image-db:latest
You should not override the postgres image entrypoint. It is designed to look for .sql files in /docker-entrypoint-initdb.d/ directory (See line in script).
You should just mount your .sql files into /docker-entrypoint-initdb.d/ and it should be processed on startup (only if database does not already exist)
I had the same issue, however, my problem occurred due to Linux user. I am using root as a runner so the problem happened because the mounting volume in the local machine did not have permissions. in this regard, I used chmod -R 777 scripts and it worked fine. Technically, you need to set permissions for both local machine and your container.

how to add a volume to an odoo that does not use volumes

Please, i already installed odoo by a method without using volumes, by the following command:
docker run -d -e POSTGRES_USER=odoo -e POSTGRES_PASSWORD=odoo --name db-old postgres:9.4
docker run -p 8066:8069 --name odoo-old --link db-old:db -t odoo:11
Now I'm using another instance of odoo that uses volume in its installation. Here is how I installed this new version of odoo:
sudo mkdir -p /volumes/docker/test_12/pg
sudo docker run -p 5001:5432 -itd -v /volumes/docker/test_12/pg:/var/lib/postgresql/data -e POSTGRES_USER=odoo -e POSTGRES_PASSWORD=odoo -e POSTGRES_DB=postgres --name db-new postgres:10.5
sudo mkdir -p /volumes/docker/test_12/addons
docker run -p 9012:8069 -itd -v /volumes/docker/test_12/addons:/mnt/extra-addons --name odoo-new --link db-new:db -t odoo:11
The problem is that I have a lot of data in the old odoo instance, I'm going to use the same odoo-old data in the new odoo-new instance, so remove odoo-old and keep odoo-new.
You can use odoo backup to migrate to new odoo server and database server in new containers. Access odoo backup feature in old odoo with browser at url /web/database/manager and get the backup. Then access your new odoo with the same url and restore your file. It will restore both database and filestore to new server. This works with or without volumes in containers if the odoo version is same in old and new.
If you need to copy other file content from odoo server, you can use "docker cp" to copy files. In your situation I would first try with backup.
Your odoo version seems to be 11 for both old and new container images. Your directory name has hints of odoo 12. Make sure you are really using same odoo version. If you try to upgrade from odoo 11 to odoo 12, you need to upgrade your database content with e.g. OCA openupgrade (https://github.com/OCA/OpenUpgrade).

How to run container using image id or name?

I have created an apache server image from tar file using below command,
cat /home/ubuntu/docker-work/softwares/httpd-2.4.27.tar.gz | docker import - httpd:2.4
The image is created successfully and its name is httpd!
I have run below command,
docker run -d -p 80:80 --name=apache httpd:2.4
which is giving error,
docker: Error response from daemon: No command specified.
How do I run the above image using the name(httpd) ?
The error that you are getting means that the image import from the tar doesn't container a default command CMD line to start the container.
Docker allows you to not specify the CMD in the docker file, however in that case you need to provide the command when doing docker run. Example:
docker run -d -p 80:80 --name=apache httpd:2.4 httpd-foreground
Where httpd-foreground is the command that will start the httpd server process inside the container.

Apache Tomcat 8 not starting within a docker container

I am experimenting with Docker and am very new to it. I am struck at a point for a long time and am not getting a way through and hence came up with this question here...
Problem Statement:
I am trying to create an image from a docker file containing Apache and lynx installation. Once done I am trying to access tomcat on 8080 of the container which is in turn forwarded to the 8082 of the host. But when running the image I never get tomcat started in the container.
The Docker file
FROM ubuntu:16.10
#Install Lynx
Run apt-get update
Run apt-get install -y lynx
#Install Curl
Run apt-get install -y curl
#Install tools: jdk
Run apt-get update
Run apt-get install -y openjdk-8-jdk wget
#Install apache tomcat
Run groupadd tomcat
Run useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat
Run cd /tmp
Run curl -O http://apache.mirrors.ionfish.org/tomcat/tomcat- 8/v8.5.12/bin/apache-tomcat-8.5.12.tar.gz
Run mkdir /opt/tomcat
Run tar xzvf apache-tomcat-8*tar.gz -C /opt/tomcat --strip-components=1
Run cd /opt/tomcat
Run chgrp -R tomcat /opt/tomcat
Run chmod -R g+r /opt/tomcat/conf
Run chmod g+x /opt/tomcat/conf
Run chown -R tomcat /opt/tomcat/webapps /opt/tomcat/work /opt/tomcat/temp opt/tomcat/logs
Run cd /opt/tomcat/bin
Expose 8080
CMD /opt/tomcat/bin/catalina.sh run && tail -f /opt/tomcat/logs/catalina.out
When the image is built I tried running the container by the two below methods
docker run -d -p 8082:8080 imageid tail -f /dev/null
While using the above, container is running but tomcat is not started inside the container and hence not accessible from localhost:8082. Also I do not see anything if I perform docker logs longcontainerid
docker run -d -p 8082:8080 imageid /path/to/catalina.sh start tail -f /dev/null
I see tomcat started when I do docker logs longconatainrid
While using the above the container is started and stopped immediately and is not running as I can see from docker ps and hence again not accessible from localhost:8082.
Can anyone please tell me where I am going wrong?
P.s. I searched a lot on the internet but could not get the thing right. Might be there is some concept that i am not getting clearly.
Looking at the docker run command documentation, the doc states that any command passed to the run will override the original CMD in your Dockerfile:
As the operator (the person running a container from the image), you can override that CMD instruction just by specifying a new COMMAND
1/ Then when you run:
docker run -d -p 8082:8080 imageid tail -f /dev/null
The container is run with COMMAND tail -f /dev/null, the original command starting tomcat is overridden.
To resolve your problem, try to run:
docker run -d -p 8082:8080 imageid
and
docker log -f containerId
To see if tomcat is correctly started.
2/ You should not use the start argument with catalina.sh. Have a look at this official tomcat Dokerfile, the team uses :
CMD ["catalina.sh", "run"]
to start tomcat (when you use start, docker ends container at the end of the shell script and tomcat will start but not maintain a running process).
3/ Finally, why don't you use tomcat official image to build your container? You could just use the :
FROM tomcat:latest
directive at the beginning of your Dockerfile, and add you required elements (new files, webapps war, settings) to the docker image.

Starting a service inside of a Dockerfile

I'm building a Docker container and in this container I am downloading the Apache service. Is it possible to automatically start the Apache service at some point? Systemctl start httpd does not work inside of the Dockerfile.
Basically, I want the apache service to be started when the docker container is started.
FROM centos:7
MAINTAINER me <me#me.com>
RUN yum update -y && yum install -y httpd php
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;
VOLUME [ "/sys/fs/cgroup" ]
EXPOSE 80
EXPOSE 443
CMD ["/usr/sbin/init"]
Try using CMD ["/usr/sbin/httpd", "-DFOREGROUND"].
You also can run :
docker run -d <image name> /usr/sbin/httpd -DFOREGROUND
According to the Docker reference (Entrypoint reference), in the scenario you describe, you would use ENTRYPOINT, as you want your web server to "immutably" start. CMD is for commands or command line options that you are likely change/be overwritten:
Command line arguments to docker run will be appended after all elements in an exec form ENTRYPOINT, and will override all elements specified using CMD. This allows arguments to be passed to the entry point, i.e., docker run -d will pass the -d argument to the entry point.
If you must override an ENTRYPOINT, e.g. for testing/diagnostics, use the specific --entrypoint option.
Further:
You can use the exec form of ENTRYPOINT to set fairly stable default commands and arguments and then use either form of CMD to set additional defaults that are more likely to be changed.
So, ENTRYPOINT for the fixed services/application part, CMD for overrideable commands or options.
Using both ENTRYPOINT and CMD allows you to set a "fixed" commands part (including options) and a "variable" part. Like so:
FROM ubuntu
ENTRYPOINT ["top", "-b"]
CMD ["-c"]
Which means, in your case you may consider to have:
ENTRYPOINT ["/usr/sbin/httpd"]
CMD ["-DFOREGROUND"]
Which allows you do:
docker run -d <image name>
when you want to run your web server in the foreground, but
docker run -d <image name> -DBACKGROUND
if you want that same server to run with the -DBACKGROUND option overriding only the -DFOREGROUND part.