我想在容器启动时设置一些配置,为此我使用的是shell脚本.但是我的容器会在脚本结束后立即退出,我尝试使用-d标志/分离模式,但它永远不会以分离模式运行.
下面是我的Dockerfile
FROM ubuntu:14.04
ADD shell.sh /usr/local/bin/shell.sh
RUN chmod 777 /usr/local/bin/shell.sh
CMD /usr/local/bin/shell.sh
Run Code Online (Sandbox Code Playgroud)
下面是我的shell脚本
#!/bin/bash
echo Hello-docker
Run Code Online (Sandbox Code Playgroud)
没有任何标志运行
docker run hello-docker
Run Code Online (Sandbox Code Playgroud)
这将在我的控制台上打印"Hello-docker"并退出
使用-itd标志运行
docker run -itd hello-docker
Run Code Online (Sandbox Code Playgroud)
我看到的差异在COMMAND部分,当我运行其他图像命令部分将显示"/ bin/bash"并将继续处于分离模式.
当我在带有shell脚本的容器中运行我的图像时,COMMAND部分将显示"/ bin/sh -c/usr/loca"和Exit.
我想运行容器直到我不能手动停止它.
编辑:
在Dockerfile中添加ENTRYPOINT指令后,这将不会执行我的shell脚本:(
FROM ubuntu:14.04
ADD shell.sh /usr/local/bin/shell.sh
RUN chmod 777 /usr/local/bin/shell.sh
CMD /usr/local/bin/shell.sh
ENTRYPOINT /bin/bash
Run Code Online (Sandbox Code Playgroud)
根据这里的 docker文档
使用备用参数运行容器时将覆盖CMD,因此如果我使用如下所示的某些参数运行docker image,则不会执行CMD指令.:(
sudo docker run -it --entrypoint=/bin/bash <imagename>
Run Code Online (Sandbox Code Playgroud) 如何在App Extension中获取设备当前方向,我尝试了以下两种方法但没有成功.
它总是返回UIDeviceOrientationUnknown
[[UIDevice currentDevice] orientation]
Run Code Online (Sandbox Code Playgroud)它显示红色消息,'sharedApplication'在iOS上不可用(App Extension)
[[UIApplication sharedApplication] statusBarOrientation];
Run Code Online (Sandbox Code Playgroud)我还添加了一个观察者,但它没有被调用.
[[NSNotificationCenter defaultCenter] addObserver:self.view selector:@selector(notification_OrientationWillChange:) name:UIApplicationWillChangeStatusBarOrientationNotification object:nil];
- (void)notification_OrientationWillChange:(NSNotification*)n
{
UIInterfaceOrientation orientation = (UIInterfaceOrientation)[[n.userInfo objectForKey:UIApplicationStatusBarOrientationUserInfoKey] intValue];
if (orientation == UIInterfaceOrientationLandscapeLeft)
[self.textDocumentProxy insertText:@"Left"];
if (orientation == UIInterfaceOrientationLandscapeRight)
[self.textDocumentProxy insertText:@"Right"];
}
Run Code Online (Sandbox Code Playgroud)那么现在如何才能获得当前的设备定位.
keyboard objective-c ios uideviceorientation ios-app-extension
我有一个问题是通过UDP在swift中通过CocoaAsyncSocket发送音频.
首先,我运行下面的代码开始监听4444 UDP端口.
vlc --demux=rawaud --rawaud-channels=1 --rawaud-samplerate=48000 udp://@:4444
Run Code Online (Sandbox Code Playgroud)
之后我在iPad2上运行我的应用程序并按连接.
import UIKit
import CocoaAsyncSocket
import AVFoundation
class ViewController: UIViewController , GCDAsyncUdpSocketDelegate {
var avAudioEngine : AVAudioEngine?
@IBAction func btnAction(sender: UIButton) {
avAudioEngine = AVAudioEngine()
let input = avAudioEngine?.inputNode
let socket = GCDAsyncUdpSocket(delegate: self, delegateQueue: dispatch_get_main_queue())
do {
try socket.bindToPort(4445)
try socket.connectToHost("192.168.0.137",onPort : 4444)
try socket.beginReceiving()
input?.installTapOnBus(0, bufferSize: 2048, format: input?.inputFormatForBus(0), block: { (buffer : AVAudioPCMBuffer, timeE: AVAudioTime) -> Void in
socket.sendData(self.toNSData(buffer), withTimeout: 0, tag: 0)
})
avAudioEngine?.prepare()
try avAudioEngine?.start()
// with …
Run Code Online (Sandbox Code Playgroud) 我正在尝试在“列”窗口小部件内扩展窗口小部件,但无法使其扩展。
当给父窗口部件恒定的高度时,布局将按预期呈现。但是,由于我删除了恒定高度的布局,并没有达到我想要的Listview的预期,因此我不应该为将用作Listview项的小部件提供恒定的高度。
下面是我的布局代码。
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
title: 'layout test',
home: Layout_test_class(),
));
}
class Layout_test_class extends StatelessWidget {
Widget cell() {
return Container(
color: Colors.yellow,
// height: 200, after un commenting this will work. but i want to make it without this
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Expanded(
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Expanded(
child: Container(
color: Colors.green,
child: Text('apple z'),
),
),
Container(
color: Colors.red,
child:Text('apple 2'),
)
],
), …
Run Code Online (Sandbox Code Playgroud) Q. 如何在分离模式下运行 docker-compose
我试图在分离模式下运行 docker-compose 但它会在运行后退出,但我可以使用 'docker run' 命令在分离模式下运行相同的图像。
使用“docker run”命令运行图像 (在分离模式下工作)
docker run -itd ubuntu:16.04
Run Code Online (Sandbox Code Playgroud)
下面是“docker ps -a”命令的输出
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d84edc987359 ubuntu:16.04 "/bin/bash" 4 seconds ago Up 3 seconds romantic_albattani
Run Code Online (Sandbox Code Playgroud)使用“docker-compose up -d”命令运行相同的图像(在分离模式下不起作用)
下面是我的 docker-compose.yml 文件
version: '3'
services:
ubuntu:
image: ubuntu:16.04
Run Code Online (Sandbox Code Playgroud)
'docker-compose ps' 命令输出
Name Command State Ports
----------------------------------------------------
composetesting_ubuntu_1 /bin/bash Exit 0
Run Code Online (Sandbox Code Playgroud)更新:当在 docker-compose.yml 文件中使用 tty: true 参数时,如下所示
version: '3'
services:
ubuntu:
image: ubuntu:16.04
tty: true
Run Code Online (Sandbox Code Playgroud)
那么控制台将不会执行任何命令,就像我输入“ls -l”命令控制台将不会响应一样。
我正在尝试使用以下shell脚本更改用户密码
#!/bin/bash
mysql.server start
mysql -u root << EOF
SET PASSWORD FOR root@'localhost' = PASSWORD(‘admin’);
EOF
Run Code Online (Sandbox Code Playgroud)
但我得到以下错误:-
第1行的错误1064(42000):您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以在第1行的“ admin”)附近使用正确的语法
如果不使用SET PASSSWORD命令,则可以使用其他方法,如使用“ create database databasename”的方法。
。
更新1:
如果我使用“ admin”或“ admin”而不是“ admin”,则会出现以下错误。
第1行的错误1064(42000):您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以在第1行的“ admin2”)附近使用正确的语法
。
更新2:
当使用-e标志时,出现以下错误
./mysql.sh:第3行:意外令牌附近的语法错误
(' ./mysql.sh: line 3:
mysql -u root -padmin -e“为root @'localhost'= PASSWORD('admin2');”设置密码”
我已使用轴承属性在地图视图上旋转相机,但无法定位相机,以便它始终显示朝顶部的导航。
下面是谷歌地图应用程序的屏幕截图,它在导航过程中自动旋转,以便它始终显示朝向顶部的路线。
下面是我的应用程序的屏幕截图,它始终显示任何方向的路线。
我使用下面的代码来旋转相机,但真的不知道如何获得所需的方位角,它总是显示在顶部方向。
let cameraPosition = GMSCameraPosition.camera(withTarget: currentLocation, zoom: self.camera.zoom, bearing: MyRide.shared.bearing, viewingAngle: 45)
let cameraUpdate = GMSCameraUpdate.setCamera(cameraPosition)
CATransaction.begin()
CATransaction.setValue(1.0, forKey: kCATransactionAnimationDuration)
self.animate(with: cameraUpdate)
CATransaction.commit()
Run Code Online (Sandbox Code Playgroud) 我想根据当前主题更改输入的文本颜色,因为文本颜色不是InputDecorationTheme
.
到目前为止,更改输入文本颜色的唯一可能方法是赋予样式,TextFormField
但当主题更改时这也不起作用+这样我需要为应用程序中可用的每个文本字段重复类似的代码。
当我尝试访问数组类型值然后获取错误时,我在字典中可能包含数组类型值时出现"对成员下标的模糊引用"这样的错误.请检查以下代码.
var occupations = [
"Malcolm": "Captain",
"Kaylee": "Mechanic",
"Layme": ["Engineer", "Docter"]
] as [String : Any]
occupations["Jayne"] = "Public Relations"
var arrOfLayme = occupations["Layme"] as! Array //getting error here, If I use NSArray instead of array all will work as expacted
print(valueOcc[0])
Run Code Online (Sandbox Code Playgroud)
当我使用NSArray类型这个代码顺利如下,我想以纯粹的方式做,不想添加Objective-c.
var arrOfLayme = occupations["Layme"] as! NSArray
Run Code Online (Sandbox Code Playgroud) 在单元测试中使用 SharedPreference 抛出错误。在一个函数中,我使用了 SharedPreference,在它的单元测试过程中,出现“绑定尚未初始化”错误以及许多其他错误。
\n\n\n下面是我的 User.dart 文件的代码
\nimport \'package:shared_preferences/shared_preferences.dart\';\n\nclass User {\n final String name;\n\n User(this.name);\n Future<bool> userName() async {\n SharedPreferences prefs = await SharedPreferences.getInstance();\n await prefs.setString("name", name);\n return true;\n }\n}
Run Code Online (Sandbox Code Playgroud)\r\n下面是测试文件的代码(User_test.dart)
\nimport \'dart:math\';\n\nimport \'package:flutter_test/flutter_test.dart\';\nimport \'package:unit_testf/user.dart\';\n\nvoid main() {\n test("a unit test", () async {\n User user = User("flutter");\n final result = await user.userName();\n expect(result, true);\n });\n}
Run Code Online (Sandbox Code Playgroud)\r\n以下是我收到的错误。
\nios ×4
dart ×3
flutter ×3
swift ×3
docker ×2
sh ×2
shell ×2
automation ×1
bash ×1
bearing ×1
dockerfile ×1
gmsmapview ×1
google-maps ×1
keyboard ×1
mysql ×1
objective-c ×1
swift3 ×1
udp ×1
unit-testing ×1