I have installed yii2 advanced template. It contains docker-compose.yml file after installation.
version: '3.2'
services:
frontend:
build: frontend
ports:
- 20080:80
volumes:
# Re-use local composer cache via host-volume
- ~/.composer-docker/cache:/root/.composer/cache:delegated
# Mount source-code for development
- ./:/app
backend:
build: backend
ports:
- 21080:80
volumes:
# Re-use local composer cache via host-volume
- ~/.composer-docker/cache:/root/.composer/cache:delegated
# Mount source-code for development
- ./:/app
mysql:
image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=verysecret
- MYSQL_DATABASE=yii2advanced
- MYSQL_USER=yii2advanced
- MYSQL_PASSWORD=secret
#pgsql:
# image: postgres:9.5
# environment:
# - POSTGRES_DB=yii2advanced
# - POSTGRES_USER=yii2advanced
# - POSTGRES_PASSWORD=secret
I don't change it and just run docker-compose up -d. I don't want to install Apache/nginx and so on. I see that this file gives me an ability to up all in docker and I'm going to use it.
So, all works nice, but I see ugly URls in my application. Something like http://localhost:21080/index.php?r=site%2Flogin. It looks like terrible. I know about urlManager, I'm trying to switch on it:
config/main.php
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>'
],
],
But now all routes give me 404. Is there some simple way to get started with Yii2 with nice URLs and without installing apache/nginx, creating virtual hosts, creating .htaccess and so on? Can I just make docker-compose up -d and have pretty URLs?
Below solution worked for me.
Add .htaccess in frontend/web and backend/web folders
RewriteEngine on
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php
Related
I want to access a secret file with docker-compose. I follow many tutorials and reproduce the structure. The container is launched but when I need to log in, the right string to enter is "/run/secrets/sec_pgadmin_default_email". I want the login to be the one inside my secret file: admin. In this secret file pgadmin_default_email.txt, there is only the word admin. I don't know if the structure of this file is good. Should it be a dictionary or something else ?
version: '3.8' services: pgadmin4:
build:
context: ./dockerfiles/
dockerfile: dockerfile_pgadmin4
image: img_pgadmin
container_name: cont_pgadmin4
ports:
- "80:80"
secrets:
- sec_pgadmin_default_email
- sec_pgadmin_default_password
environment:
- PGADMIN_LISTEN_PORT=80
- PGADMIN_DEFAULT_EMAIL=/run/secrets/sec_pgadmin_default_email
- PGADMIN_DEFAULT_PASSWORD=/run/secrets/sec_pgadmin_default_password
secrets:
sec_pgadmin_default_email:
file: ./.secrets/pgadmin_default_email.txt
sec_pgadmin_default_password:
file: ./.secrets/pgadmin_default_password.txt
PS I just use the command docker-compose up -d, without swarn things or else. I don't define external secrets and I prefer not. Is it possible ?
the environment variable will be set to the path of the file containing the actual value. Not the actual value itself.
For example, in Go you could do something like:
var pgAdminDefaultEmailFile = os.Getenv("PGADMIN_DEFAULT_EMAIL") // get the file
pgAdminDefaultEmailValue, err := ioutil.ReadFile(pgAdminDefaultEmailFile) // get the value
if err != nil {
log.Fatal(err)
}
pgAdminDefaultEmail = string(pgAdminDefaultEmailValue) // parse out the value
I'm trying to setup selenoid and I'm having trouble with dockercomposer, it throws exception as below:
yaml.parser.ParserError: while parsing a flow mapping in "./docker-compose.yml", line 1, column 1 expected ',' or '}', but got '{' in "./docker-compose.yml", line 2, column 1
when I try to run docker command "$ sudo docker-compose up -d"
I'm in the terminal with same folder where docker-compose.yml present and content is as below,
version: '3'
services:
selenoid:
network_mode: bridge
image: aerokube/selenoid
volumes:
- "/docker:/etc/selenoid"
- "/var/run/docker.sock:/var/run/docker.sock"
- "/docker/video:/opt/selenoid/video"
environment:
- OVERRIDE_VIDEO_OUTPUT_DIR=/opt/selenium/video
- TZ=Europe/Amsterdam
command: ["-conf", "/etc/selenoid/browsers.json", "-video-output-dir", "/opt/selenoid/video"]
ports:
- "4444:4444"
I've also tried many online yml parsers and there is nothing wrong with yml file. Any help would be much appreciated.
Thanks
Sorry being late to answer my own post, there was nothing wrong with YML file, I should have created/edited it using programming editors such as IntelliJ, but I was editing and saving it using EditText. All worked fine after editing them and saving using IntelliJ in mac.
ok this is driving me nuts already. What I just want to do is launch php:5.6-apache image and mount my ./web to /var/www/html by having the following docker-compose.yml file:
version: '2'
services:
apache:
image: php:5.6-apache
volumes:
- ./web:/var/www/html
ports:
- 8081:80
Launching it with docker-compose up.
For some unknown reason this results in empty /var/www/html folder, although it should contain what I have in ./web.
Or I am doing it wrong?
Well, it turned out that for some reason windows firewall prevented folder sharing. It seems that it was because DockerNat network was listed among Public networks, so I had to run the following commands in elevated power shell:
$Profile = Get-NetConnectionProfile -InterfaceAlias "vEthernet (DockerNAT)"
$Profile.NetworkCategory = "Private"
Set-NetConnectionProfile -InputObject $Profile
Then I was able to enable drive sharing in docker settings and then mounted folders became filled with files.
[UPDATE 2018-05-03] There's a good gist that will put dockerNat network to private when you restart docker. All you have to do is modify MobyLinux.ps1 file located at C:\Program Files\Docker\Docker\resources by adding include at 86, function at 182-186 and modifying lines try/catch statement at 399-409 to include Set-Switch-Private function calls.
Is it possible with docker-compose to mimic following?
the .env file:
...
if [ -f "another.env" ]; then
. ./another.env
fi
....
I am getting no errors, just nothing happens.
Just try with env_file section:
version '3.6'
your-service:
env_file: ./another.env
For more information, have a look to docker-compose environment conf doc
Example:
my-server:
image: my-server:latest
ports:
- 1234:1234
proxy:
image: lb:latest
environment:
- BACKEND=${VAR}??? # must be resolve as 'my-server'
The server name can be changed to any name, but the proxy has a entry-point script where the variable will be substituted in the BACKEND to config.
You can use a .env file to define your variable. This file will be placed in the same directory as your docker-compose.yml file.
When you run docker-compose, it will read this value and use it. Using your example, your .env file would look something like this:
VAR=my-server
and, the line:
- BACKEND=${VAR}??? # must be resolve as 'my-server'
would become just:
- BACKEND=${VAR}
or
BACKEND: ${VAR}